~captainepoch/husky

7507a9cf166dc0835519cc50fd51236de36b9f90 — Adolfo Santiago a month ago e07467b
Fix NavigationActivity onCreate method

Add Splash, Login classes (refactor)
A husky/app/src/main/java/com/keylesspalace/tusky/core/extensions/AlertDialogExt.kt => husky/app/src/main/java/com/keylesspalace/tusky/core/extensions/AlertDialogExt.kt +18 -0
@@ 0,0 1,18 @@
package com.keylesspalace.tusky.core.extensions

import android.R.id
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.widget.TextView
import androidx.appcompat.app.AlertDialog

fun AlertDialog.Builder.dialogWithLink(message: String, positiveButton: String) {
    val dialog = AlertDialog.Builder(context)
        .setMessage(message)
        .setPositiveButton(positiveButton, null)
        .show()

    val text = dialog.window?.findViewById<TextView>(id.message)
    text?.autoLinkMask = Linkify.ALL
    text?.movementMethod = LinkMovementMethod.getInstance()
}

M husky/app/src/main/java/com/keylesspalace/tusky/core/navigation/NavigationActivity.kt => husky/app/src/main/java/com/keylesspalace/tusky/core/navigation/NavigationActivity.kt +2 -5
@@ 20,7 20,6 @@
package com.keylesspalace.tusky.core.navigation

import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import com.keylesspalace.tusky.core.di.HuskyServices
import com.keylesspalace.tusky.core.extensions.viewBinding


@@ 40,8 39,8 @@ class NavigationActivity : AppCompatActivity(), SimpleStateChanger.NavigationHan
    private val binding by viewBinding(ActivityNavigationBinding::inflate)
    private lateinit var fragmentStateChanger: DefaultFragmentStateChanger

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        initNavigation()


@@ 60,8 59,6 @@ class NavigationActivity : AppCompatActivity(), SimpleStateChanger.NavigationHan
    }

    private fun initNavigation() {
        Timber.d("Init setup navigation")

        fragmentStateChanger = DefaultFragmentStateChanger(
            supportFragmentManager,
            binding.fragmentContainer.id

M husky/app/src/main/java/com/keylesspalace/tusky/core/ui/navigation/BaseKey.kt => husky/app/src/main/java/com/keylesspalace/tusky/core/ui/navigation/BaseKey.kt +1 -1
@@ 23,5 23,5 @@ import com.zhuinden.simplestackextensions.fragments.DefaultFragmentKey

abstract class BaseKey : DefaultFragmentKey() {

    override fun getFragmentTag(): String = this.javaClass.simpleName
    override fun getFragmentTag(): String = this.javaClass.name
}

M husky/app/src/main/java/com/keylesspalace/tusky/core/ui/navigation/BaseServiceKey.kt => husky/app/src/main/java/com/keylesspalace/tusky/core/ui/navigation/BaseServiceKey.kt +1 -1
@@ 23,5 23,5 @@ import com.zhuinden.simplestackextensions.services.DefaultServiceProvider

abstract class BaseServiceKey : BaseKey(), DefaultServiceProvider.HasServices {

    override fun getScopeTag(): String = this.javaClass.simpleName
    override fun getScopeTag(): String = this.javaClass.name
}

A husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/fragments/LoginFragment.kt => husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/fragments/LoginFragment.kt +44 -0
@@ 0,0 1,44 @@
package com.keylesspalace.tusky.refactor_features.login.view.fragments

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.core.extensions.dialogWithLink
import com.keylesspalace.tusky.core.extensions.viewBinding
import com.keylesspalace.tusky.core.extensions.viewObserve
import com.keylesspalace.tusky.core.ui.fragment.BaseFragment
import com.keylesspalace.tusky.databinding.ActivityLoginBinding
import com.keylesspalace.tusky.refactor_features.login.view.viewmodel.LoginViewModel
import com.zhuinden.simplestackextensions.fragmentsktx.lookup

class LoginFragment : BaseFragment(R.layout.activity_login) {

    private val binding by viewBinding(ActivityLoginBinding::bind)
    private val viewModel by lazy { lookup<LoginViewModel>() }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        initObservers()
        initListeners()
    }

    private fun initObservers() {
        with(viewModel) {
            viewObserve(verifyUrl, ::handleVerifyUrl)
        }
    }

    private fun initListeners() {
        binding.whatsAnInstanceTextView.setOnClickListener {
            AlertDialog.Builder(requireActivity()).dialogWithLink(
                getString(R.string.dialog_whats_an_instance),
                getString(R.string.action_close)
            )
        }
    }

    private fun handleVerifyUrl(isValid: Boolean?) {
    }
}

A husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/navigation/LoginKey.kt => husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/navigation/LoginKey.kt +21 -0
@@ 0,0 1,21 @@
package com.keylesspalace.tusky.refactor_features.login.view.navigation

import androidx.fragment.app.Fragment
import com.keylesspalace.tusky.core.ui.navigation.BaseServiceKey
import com.keylesspalace.tusky.refactor_features.login.view.fragments.LoginFragment
import com.keylesspalace.tusky.refactor_features.login.view.viewmodel.LoginViewModel
import com.zhuinden.simplestack.ServiceBinder
import com.zhuinden.simplestackextensions.servicesktx.add
import kotlinx.android.parcel.Parcelize

@Parcelize
class LoginKey : BaseServiceKey() {

    override fun instantiateFragment(): Fragment {
        return LoginFragment()
    }

    override fun bindServices(serviceBinder: ServiceBinder) {
        serviceBinder.add(LoginViewModel())
    }
}

A husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/viewmodel/LoginViewModel.kt => husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/viewmodel/LoginViewModel.kt +36 -0
@@ 0,0 1,36 @@
package com.keylesspalace.tusky.refactor_features.login.view.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.keylesspalace.tusky.core.ui.viewmodel.BaseViewModel
import com.zhuinden.statebundle.StateBundle
import timber.log.Timber

class LoginViewModel : BaseViewModel() {

    private val mVerifyUrl = MutableLiveData<Boolean>()
    val verifyUrl: LiveData<Boolean>
        get() = mVerifyUrl

    override fun toBundle(): StateBundle {
        val stateBundle = StateBundle()

        stateBundle.putBoolean(LoginViewModelKeys.Bundle.VERIFY_URL, mVerifyUrl.value ?: false)

        Timber.d("TO BUNDLE")

        return stateBundle
    }

    override fun fromBundle(bundle: StateBundle?) {
        bundle?.let {
            mVerifyUrl.value = it.getBoolean(LoginViewModelKeys.Bundle.VERIFY_URL)

            Timber.d("FROM BUNDLE")
        }
    }

    fun verifyUrl(url: String?) {
        mVerifyUrl.value = false
    }
}

A husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/viewmodel/LoginViewModelKeys.kt => husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/login/view/viewmodel/LoginViewModelKeys.kt +8 -0
@@ 0,0 1,8 @@
package com.keylesspalace.tusky.refactor_features.login.view.viewmodel

sealed class LoginViewModelKeys {

    object Bundle {
        const val VERIFY_URL = "verifyUrl"
    }
}

M husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/splash/view/fragments/SplashFragment.kt => husky/app/src/main/java/com/keylesspalace/tusky/refactor_features/splash/view/fragments/SplashFragment.kt +12 -2
@@ 1,16 1,26 @@
package com.keylesspalace.tusky.refactor_features.splash.view.fragments

import android.os.Bundle
import android.view.View
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.core.extensions.viewBinding
import com.keylesspalace.tusky.core.ui.fragment.BaseFragment
import com.keylesspalace.tusky.databinding.FragmentSplashBinding
import com.keylesspalace.tusky.refactor_features.login.view.navigation.LoginKey
import com.keylesspalace.tusky.refactor_features.splash.view.viewmodel.SplashViewModel
import com.zhuinden.simplestack.History
import com.zhuinden.simplestack.StateChange
import com.zhuinden.simplestackextensions.fragmentsktx.backstack
import com.zhuinden.simplestackextensions.fragmentsktx.lookup


class SplashFragment : BaseFragment(R.layout.fragment_splash) {

    private val binding by viewBinding(FragmentSplashBinding::bind)
    private val viewModel: SplashViewModel by lazy { lookup() }
    private val viewModel by lazy { lookup<SplashViewModel>() }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        backstack.setHistory(History.single(LoginKey()), StateChange.FORWARD)
    }
}

M husky/app/src/main/res/layout/activity_login.xml => husky/app/src/main/res/layout/activity_login.xml +15 -12
@@ 23,11 23,11 @@
            android:padding="16dp">

            <ImageView
                android:id="@+id/loginLogo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="50dp"
                android:contentDescription="@null"
                android:id="@+id/loginLogo"
                app:srcCompat="@drawable/elephant_friend" />

            <LinearLayout


@@ 52,21 52,22 @@
                        android:ems="10"
                        android:inputType="textUri" />
                </com.google.android.material.textfield.TextInputLayout>
                

                <LinearLayout
                    android:id="@+id/extendedSettings"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="gone"
                    android:orientation="vertical">
                    android:orientation="vertical"
                    android:visibility="gone">

                    <com.google.android.material.textfield.TextInputLayout
                        style="@style/TuskyTextInput"
                        android:layout_width="250dp"
                        android:layout_height="wrap_content"
                        android:hint="@string/hint_appname"
                        android:layout_marginTop="8dp"
                        android:hint="@string/hint_appname"
                        app:errorEnabled="true">
                    

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/appNameEditText"
                            android:layout_width="match_parent"


@@ 74,15 75,15 @@
                            android:ems="10"
                            android:inputType="textUri" />
                    </com.google.android.material.textfield.TextInputLayout>
                    

                    <com.google.android.material.textfield.TextInputLayout
                        style="@style/TuskyTextInput"
                        android:layout_width="250dp"
                        android:layout_height="wrap_content"
                        android:hint="@string/hint_website"
                        android:layout_marginTop="8dp"
                        android:hint="@string/hint_website"
                        app:errorEnabled="true">
                        

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/websiteEditText"
                            android:layout_width="match_parent"


@@ 91,12 92,13 @@
                            android:inputType="textUri" />
                    </com.google.android.material.textfield.TextInputLayout>
                </LinearLayout>
                

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:orientation="horizontal">

                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/loginButton"
                        style="@style/TuskyButton"


@@ 109,13 111,13 @@
                    <com.google.android.material.button.MaterialButton
                        android:id="@+id/settingsButton"
                        style="@style/TuskyButton"
                        android:padding="4dp"
                        android:layout_width="32dp"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="4dp"
                        app:icon="@drawable/ic_settings" />
                </LinearLayout>
                

                <TextView
                    android:id="@+id/whatsAnInstanceTextView"
                    android:layout_width="250dp"


@@ 146,6 148,7 @@
            </LinearLayout>

        </LinearLayout>

    </ScrollView>

    <androidx.appcompat.widget.Toolbar