Skip to content

Instantly share code, notes, and snippets.

View luck-alex13's full-sized avatar

Alexandr Novikov luck-alex13

  • Russia
View GitHub Profile
@luck-alex13
luck-alex13 / LoginFragment.kt
Last active January 28, 2024 14:14
MutableStateFlow with Fragment and ViewModel
@AndroidEntryPoint
class LoginFragment : BaseBindingFragment<LoginFragmentBinding>() {
companion object {
fun screen() = FragmentScreen { LoginFragment() }
}
private val viewModel: LoginViewModel by viewModels()
override val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> LoginFragmentBinding =
@luck-alex13
luck-alex13 / AuthActivityVM.kt
Created September 17, 2020 11:21
Примеры кода
class AuthActivityVM(application: Application) : BaseAndroidViewModel(application), LifecycleObserver {
var authClient = DokiMainClient.create(UserConfig.getServerUrl())
fun changePass(oldPass: String, newPass: String) {
vmState.postValue(ViewModelState.ProgressState(true))
compositeDisposable.add(
makeAsync(authClient.changePassword(oldPass, newPass))
.subscribe({
vmState.postValue(ViewModelState.SuccessChangePass())
@luck-alex13
luck-alex13 / TriangleLabelView.java
Last active September 2, 2019 05:24
TriangleLabelView for CardView
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.*;
import android.os.Build;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.StringRes;
import androidx.core.content.ContextCompat;
import UIKit
public extension UIViewController {
func setTitle(title:String) {
self.title = title
}
func setEmptyBackArrow(){
// удаляет текст возле кнопки назад
@luck-alex13
luck-alex13 / ValidationHelper.java
Created March 5, 2019 13:48
Email and password validation helper
package com.example.user.testapphandh;
import android.util.Patterns;
import java.util.regex.Pattern;
public class ValidationHelper {
/*
( # Start of group
@luck-alex13
luck-alex13 / back_button.xml
Created April 14, 2018 13:26
default android back arrow button
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="?attr/homeAsUpIndicator"
android:background="?attr/selectableItemBackgroundBorderless"/>
@luck-alex13
luck-alex13 / build.gradle
Created April 14, 2018 12:47
Автоматическое именование apk при сборке
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.flavorName}-${variant.buildType.name}-${variant.versionCode}.apk"
}
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "appName-${variant.buildType.name}-vCode-${variant.versionCode}-vName-${variant.versionName}.apk"
}
}
public class AbstractFragment extends Fragment {
protected int fragmentId, toolbarTitle;
private FragmentActivity activity;
public AbstractFragment() {
}
@luck-alex13
luck-alex13 / sendImplicitIntent
Created March 28, 2018 03:21
Стартует сервис у которого в <intent-filter> прописан ACTION_CUSTOM_EVENT. Таким же образом можно стартануть активити
public static Intent convertImplicitIntentToExplicitIntent(Intent implicitIntent, Context context) {
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentServices(implicitIntent, 0);
if (resolveInfoList == null || resolveInfoList.size() != 1) {
return null;
}
ResolveInfo serviceInfo = resolveInfoList.get(0);
ComponentName component = new ComponentName(serviceInfo.serviceInfo.packageName, serviceInfo.serviceInfo.name);
Intent explicitIntent = new Intent(implicitIntent);
explicitIntent.setComponent(component);
@luck-alex13
luck-alex13 / sendImplicitBroadcast
Created March 28, 2018 03:17
Отправляет кастомный броадкаст (для Android 8)
private static void sendImplicitBroadcast(Context ctxt, Intent i) {
PackageManager pm = ctxt.getPackageManager();
List<ResolveInfo> matches = pm.queryBroadcastReceivers(i, 0);
for (ResolveInfo resolveInfo : matches) {
Intent explicit = new Intent(i);
ComponentName cn =
new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);