From f72edf7ec55ead6ad36dd1297b5c419014447484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Thu, 20 Jun 2019 17:59:27 +0200 Subject: [PATCH 1/6] REF: migrate to androidx --- build.gradle | 4 +- demo/build.gradle | 31 +++-- .../android/appskeletondemo/MainActivity.kt | 8 +- .../main/testdagger/AppComponent.kt | 1 - .../main/testdagger/TestDaggerFragment.kt | 4 +- .../main/testdagger/TestDaggerViewModel.kt | 6 +- .../main/testdagger/TestManager.kt | 2 +- .../main/testviewmodel/TestvmFragment.kt | 2 +- .../main/testviewmodel/TestvmViewModel.kt | 2 +- .../main/res/layout/activity_custom_view.xml | 4 +- demo/src/main/res/xml/main_preferences.xml | 10 +- gradle/wrapper/gradle-wrapper.properties | 4 +- skeleton/build.gradle | 35 +++--- .../appskeleton/activity/BaseMainActivity.kt | 4 +- .../DefaultDrawerActivityViewHelper.kt | 14 +-- .../activity/DrawerActivityViewHelper.kt | 13 +- .../appskeleton/fragment/BaseFragment.kt | 6 +- .../fragment/BaseFragmentManager.kt | 32 +++-- .../fragment/BasePreferenceFragment.kt | 2 +- .../appskeleton/fragment/BaseViewModel.kt | 3 +- .../fragment/BaseViewModelFragment.kt | 3 +- .../permission/IPermissionManagerListener.kt | 9 -- .../permission/PermissionManager.kt | 113 ------------------ .../src/main/res/layout/activity_main.xml | 7 +- skeleton/src/main/res/layout/main_layout.xml | 11 +- skeleton/src/main/res/values/values.xml | 2 +- 26 files changed, 110 insertions(+), 222 deletions(-) delete mode 100644 skeleton/src/main/java/com/qase/android/appskeleton/permission/IPermissionManagerListener.kt delete mode 100644 skeleton/src/main/java/com/qase/android/appskeleton/permission/PermissionManager.kt diff --git a/build.gradle b/build.gradle index dfdece8..5394b4c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.51' + ext.kotlin_version = '1.3.31' ext.architecture_components_version = '1.1.1' repositories { google() @@ -9,7 +9,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.4.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/demo/build.gradle b/demo/build.gradle index 7d2436c..aea7d1e 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -4,11 +4,11 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { applicationId "com.qase.android.appskeletondemo" minSdkVersion 16 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -28,29 +28,28 @@ kapt { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation project(':skeleton') + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.core:core-ktx:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06' + implementation 'com.google.android.material:material:1.1.0-alpha07' + implementation 'androidx.fragment:fragment:1.1.0-beta01' + implementation 'androidx.preference:preference:1.1.0-beta01' - implementation "com.android.support:support-core-utils:27.1.1" - implementation 'com.android.support:appcompat-v7:27.1.1' - // PreferenceFragmentCompat (because we use android.support.v4.app.Fragment) - implementation 'com.android.support:preference-v7:27.1.1' - implementation 'com.android.support:multidex:1.0.3' - implementation 'com.android.support:design:27.1.1' // Architecture Components - implementation "android.arch.lifecycle:runtime:$architecture_components_version" - implementation "android.arch.lifecycle:extensions:$architecture_components_version" - kapt "android.arch.lifecycle:compiler:$architecture_components_version" + implementation "androidx.lifecycle:lifecycle-runtime:2.2.0-alpha01" + implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01" + kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01" // RxJava - implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' - implementation 'io.reactivex.rxjava2:rxjava:2.1.14' + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' + implementation 'io.reactivex.rxjava2:rxjava:2.2.8' //Dagger implementation 'com.google.dagger:dagger:2.11' diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/MainActivity.kt b/demo/src/main/java/com/qase/android/appskeletondemo/MainActivity.kt index bc52acb..dfbf77f 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/MainActivity.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/MainActivity.kt @@ -2,12 +2,12 @@ package com.qase.android.appskeletondemo import android.content.Intent import android.os.Bundle -import android.support.design.widget.NavigationView -import android.support.v4.view.GravityCompat -import android.support.v4.widget.DrawerLayout import android.view.Menu import android.view.MenuItem import android.view.View +import androidx.core.view.GravityCompat +import androidx.drawerlayout.widget.DrawerLayout +import com.google.android.material.navigation.NavigationView import com.qase.android.appskeleton.activity.BaseActivityViewHelper import com.qase.android.appskeleton.activity.BaseMainActivity import com.qase.android.appskeleton.activity.DefaultDrawerActivityViewHelper @@ -15,7 +15,7 @@ import com.qase.android.appskeletondemo.main.preference.SettingsFragment import com.qase.android.appskeletondemo.main.test.TestFragment import com.qase.android.appskeletondemo.main.test.TestFragment2 import com.qase.android.appskeletondemo.main.test.TestFragment3 -import com.qase.android.appskeletondemo.main.testviewmodel.TestDaggerFragment +import com.qase.android.appskeletondemo.main.testdagger.TestDaggerFragment import com.qase.android.appskeletondemo.main.testviewmodel.TestvmFragment class MainActivity : BaseMainActivity(), NavigationView.OnNavigationItemSelectedListener { diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/AppComponent.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/AppComponent.kt index 6fbdb02..d0ea78c 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/AppComponent.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/AppComponent.kt @@ -1,7 +1,6 @@ package com.qase.android.appskeletondemo.main.testdagger import com.qase.android.appskeleton.BaseAppComponent -import com.qase.android.appskeletondemo.main.testviewmodel.TestDaggerViewModel import dagger.Component import javax.inject.Singleton diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt index 9dabd4e..b5efdbb 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt @@ -1,10 +1,10 @@ -package com.qase.android.appskeletondemo.main.testviewmodel +package com.qase.android.appskeletondemo.main.testdagger -import android.arch.lifecycle.Observer import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.Observer import com.qase.android.appskeleton.fragment.BaseBundle import com.qase.android.appskeleton.fragment.BaseViewModelFragment import com.qase.android.appskeletondemo.R diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerViewModel.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerViewModel.kt index 94ea183..99be467 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerViewModel.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerViewModel.kt @@ -1,10 +1,8 @@ -package com.qase.android.appskeletondemo.main.testviewmodel +package com.qase.android.appskeletondemo.main.testdagger -import android.arch.lifecycle.MutableLiveData +import androidx.lifecycle.MutableLiveData import com.qase.android.appskeleton.fragment.BaseBundle import com.qase.android.appskeleton.fragment.InjectedBaseViewModel -import com.qase.android.appskeletondemo.main.testdagger.AppComponent -import com.qase.android.appskeletondemo.main.testdagger.TestManager import javax.inject.Inject class TestDaggerViewModel : InjectedBaseViewModel() { diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestManager.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestManager.kt index f9f399e..5b157c5 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestManager.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestManager.kt @@ -1,6 +1,6 @@ package com.qase.android.appskeletondemo.main.testdagger -import android.arch.lifecycle.MutableLiveData +import androidx.lifecycle.MutableLiveData import io.reactivex.Observable import io.reactivex.schedulers.Schedulers import java.lang.Thread.sleep diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmFragment.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmFragment.kt index 6bf61ba..1c43844 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmFragment.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmFragment.kt @@ -1,10 +1,10 @@ package com.qase.android.appskeletondemo.main.testviewmodel -import android.arch.lifecycle.Observer import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.lifecycle.Observer import com.qase.android.appskeleton.fragment.BaseBundle import com.qase.android.appskeleton.fragment.BaseViewModelFragment import com.qase.android.appskeletondemo.R diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmViewModel.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmViewModel.kt index 974ec01..8d72422 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmViewModel.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testviewmodel/TestvmViewModel.kt @@ -1,6 +1,6 @@ package com.qase.android.appskeletondemo.main.testviewmodel -import android.arch.lifecycle.MutableLiveData +import androidx.lifecycle.MutableLiveData import com.qase.android.appskeleton.fragment.BaseBundle import com.qase.android.appskeleton.fragment.BaseViewModel import io.reactivex.Observable diff --git a/demo/src/main/res/layout/activity_custom_view.xml b/demo/src/main/res/layout/activity_custom_view.xml index 4ff34b2..f9e97f6 100644 --- a/demo/src/main/res/layout/activity_custom_view.xml +++ b/demo/src/main/res/layout/activity_custom_view.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/demo/src/main/res/xml/main_preferences.xml b/demo/src/main/res/xml/main_preferences.xml index 9d1a4bc..e295f2d 100644 --- a/demo/src/main/res/xml/main_preferences.xml +++ b/demo/src/main/res/xml/main_preferences.xml @@ -1,19 +1,19 @@ - + - - - - \ No newline at end of file + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6383662..34a3fb9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri May 04 10:42:02 CEST 2018 +#Thu Jun 20 15:05:12 CEST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/skeleton/build.gradle b/skeleton/build.gradle index c28f635..3380cb4 100644 --- a/skeleton/build.gradle +++ b/skeleton/build.gradle @@ -4,11 +4,11 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' android { - compileSdkVersion 27 + compileSdkVersion 28 defaultConfig { minSdkVersion 16 - targetSdkVersion 27 + targetSdkVersion 28 versionCode 1 versionName "0.2.0" @@ -35,27 +35,34 @@ kapt { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:27.1.1' +// implementation 'com.android.support:appcompat-v7:27.1.1' testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - androidTestImplementation 'com.android.support:multidex:1.0.3' +// androidTestImplementation 'com.android.support.test:runner:1.0.2' +// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +// androidTestImplementation 'com.android.support:multidex:1.0.3' - implementation 'com.android.support:multidex:1.0.3' - implementation 'com.android.support:preference-v7:27.1.1' +// implementation 'com.android.support:multidex:1.0.3' +// implementation 'com.android.support:preference-v7:27.1.1' - implementation 'com.android.support:design:27.1.1' +// implementation 'com.android.support:design:27.1.1' + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.core:core-ktx:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06' + implementation 'com.google.android.material:material:1.1.0-alpha07' + implementation 'androidx.fragment:fragment:1.1.0-beta01' + implementation 'androidx.preference:preference:1.1.0-beta01' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // Architecture Components - implementation "android.arch.lifecycle:runtime:$architecture_components_version" - implementation "android.arch.lifecycle:extensions:$architecture_components_version" - kapt "android.arch.lifecycle:compiler:$architecture_components_version" + implementation "androidx.lifecycle:lifecycle-runtime:2.2.0-alpha01" + implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01" + kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01" //RxJava - implementation 'io.reactivex.rxjava2:rxandroid:2.0.2' - implementation 'io.reactivex.rxjava2:rxjava:2.1.14' + implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' + implementation 'io.reactivex.rxjava2:rxjava:2.2.8' } repositories { diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/activity/BaseMainActivity.kt b/skeleton/src/main/java/com/qase/android/appskeleton/activity/BaseMainActivity.kt index f6ac558..1d064db 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/activity/BaseMainActivity.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/activity/BaseMainActivity.kt @@ -1,9 +1,9 @@ package com.qase.android.appskeleton.activity import android.os.Bundle -import android.support.design.widget.NavigationView -import android.support.v7.app.AppCompatActivity import android.util.Log +import androidx.appcompat.app.AppCompatActivity +import com.google.android.material.navigation.NavigationView import com.qase.android.appskeleton.BaseApp /** diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/activity/DefaultDrawerActivityViewHelper.kt b/skeleton/src/main/java/com/qase/android/appskeleton/activity/DefaultDrawerActivityViewHelper.kt index 6edaf9c..993263a 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/activity/DefaultDrawerActivityViewHelper.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/activity/DefaultDrawerActivityViewHelper.kt @@ -1,12 +1,12 @@ package com.qase.android.appskeleton.activity -import android.support.annotation.DrawableRes -import android.support.annotation.LayoutRes -import android.support.annotation.MenuRes -import android.support.annotation.StringRes -import android.support.design.widget.NavigationView import android.widget.ImageView import android.widget.TextView +import androidx.annotation.DrawableRes +import androidx.annotation.LayoutRes +import androidx.annotation.MenuRes +import androidx.annotation.StringRes +import com.google.android.material.navigation.NavigationView import com.qase.android.appskeleton.R import kotlinx.android.synthetic.main.activity_main.* @@ -34,8 +34,8 @@ open class DefaultDrawerActivityViewHelper(listener: NavigationView.OnNavigation constructor(listener: NavigationView.OnNavigationItemSelectedListener, @MenuRes menuRes: Int? = null, @DrawableRes headerIconRes: Int? = null, - @StringRes headerTextPrimary: String? = null, - @StringRes headerTextSecondary: String? = null) : this(listener) { + headerTextPrimary: String? = null, + headerTextSecondary: String? = null) : this(listener) { this.menuRes = menuRes this.headerIconRes = headerIconRes this.headerTextPrimary = headerTextPrimary diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/activity/DrawerActivityViewHelper.kt b/skeleton/src/main/java/com/qase/android/appskeleton/activity/DrawerActivityViewHelper.kt index cab0d0c..d7f4df7 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/activity/DrawerActivityViewHelper.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/activity/DrawerActivityViewHelper.kt @@ -1,12 +1,13 @@ package com.qase.android.appskeleton.activity -import android.support.annotation.LayoutRes -import android.support.annotation.MenuRes -import android.support.annotation.StringRes -import android.support.design.widget.NavigationView -import android.support.v4.widget.DrawerLayout -import android.support.v7.app.ActionBarDrawerToggle + import android.view.View +import androidx.annotation.LayoutRes +import androidx.annotation.MenuRes +import androidx.annotation.StringRes +import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.drawerlayout.widget.DrawerLayout +import com.google.android.material.navigation.NavigationView import com.qase.android.appskeleton.R import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.main_layout.* diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseFragment.kt b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseFragment.kt index d6d2c6f..7336cb1 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseFragment.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseFragment.kt @@ -2,13 +2,13 @@ package com.qase.android.appskeleton.fragment import android.content.Context import android.os.Bundle -import android.support.v4.app.Fragment import android.util.Log import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import com.qase.android.appskeleton.BaseApp import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject @@ -64,7 +64,7 @@ abstract class BaseFragment : Fragment(), IFragment : Fragment(), IFragment, BundleType : BaseBundle> changeFragment(fragmentClassFullName: String, key: String, extras: BundleType? = null, rFragContainer: Int = MAIN_CONTAINER_ID, frManager: FragmentManager? = null, clearBackstack: Boolean = false): FragmentType { val fragmentClass = Class.forName(fragmentClassFullName) @@ -90,7 +92,7 @@ class BaseFragmentManager { val transaction = fm.beginTransaction() // Replace whatever is in the fragment_container view with this fragment - transaction.replace(rFragContainer, fragment as Fragment?, key) + transaction.replace(rFragContainer, fragment as Fragment, key) // Add the transaction to the back stack so the user can navigate back if (addToBackStack) { @@ -132,8 +134,10 @@ class BaseFragmentManager { val transaction = fm.beginTransaction() val fragment = fm.findFragmentByTag(key) - transaction.detach(fragment) - transaction.commit() + if (fragment != null) { + transaction.detach(fragment) + transaction.commit() + } } /** @@ -146,7 +150,7 @@ class BaseFragmentManager { * * * @return Fragment instance */ - fun , BundleType : BaseBundle> getFragment(fragmentClass: Class, key: String, fm: FragmentManager, extras: BundleType?): FragmentType? { + fun , BundleType : BaseBundle> getFragment(fragmentClass: Class, key: String, fm: FragmentManager, extras: BundleType?): FragmentType { try { // Check if fragment exists val existFragment = fm.findFragmentByTag(key) @@ -172,8 +176,7 @@ class BaseFragmentManager { } catch (ex: Exception) { Log.e(LOG_TAG, "Get fragment failed!") ex.printStackTrace() - - return null + throw ex } } @@ -194,10 +197,12 @@ class BaseFragmentManager { val name = fm.getBackStackEntryAt(index).name val fragment = fm.findFragmentByTag(name) - val trans = fm.beginTransaction() - trans.remove(fragment) - trans.commit() - fm.popBackStack() + if (fragment != null) { + val trans = fm.beginTransaction() + trans.remove(fragment) + trans.commit() + fm.popBackStack() + } } /** @@ -270,6 +275,7 @@ class BaseFragmentManager { if (backStackCount > 0) { fragmentTag = fragmentManager.getBackStackEntryAt(backStackCount - 1).name + ?: throw RuntimeException("No name for fragment") } return fragmentTag diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BasePreferenceFragment.kt b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BasePreferenceFragment.kt index 83086b5..e0c88e8 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BasePreferenceFragment.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BasePreferenceFragment.kt @@ -1,10 +1,10 @@ package com.qase.android.appskeleton.fragment import android.os.Bundle -import android.support.v7.preference.PreferenceFragmentCompat import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.preference.PreferenceFragmentCompat import com.qase.android.appskeleton.BaseApp import io.reactivex.subjects.BehaviorSubject import io.reactivex.subjects.Subject diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModel.kt b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModel.kt index 1376650..e94bc1c 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModel.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModel.kt @@ -1,5 +1,6 @@ package com.qase.android.appskeleton.fragment -import android.arch.lifecycle.ViewModel +import androidx.lifecycle.ViewModel + abstract class BaseViewModel : ViewModel() diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModelFragment.kt b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModelFragment.kt index f720ed6..5b9be39 100644 --- a/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModelFragment.kt +++ b/skeleton/src/main/java/com/qase/android/appskeleton/fragment/BaseViewModelFragment.kt @@ -1,6 +1,7 @@ package com.qase.android.appskeleton.fragment -import android.arch.lifecycle.ViewModelProviders +import androidx.lifecycle.ViewModelProviders + /** * Created by tomas on 22.08.2017. diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/permission/IPermissionManagerListener.kt b/skeleton/src/main/java/com/qase/android/appskeleton/permission/IPermissionManagerListener.kt deleted file mode 100644 index 4f46c2d..0000000 --- a/skeleton/src/main/java/com/qase/android/appskeleton/permission/IPermissionManagerListener.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.qase.android.appskeleton.permission - -interface IPermissionManagerListener { - - fun onPermissionGranted(permission: String) - - fun onPermissionDenied(permission: String) - -} diff --git a/skeleton/src/main/java/com/qase/android/appskeleton/permission/PermissionManager.kt b/skeleton/src/main/java/com/qase/android/appskeleton/permission/PermissionManager.kt deleted file mode 100644 index dde52bb..0000000 --- a/skeleton/src/main/java/com/qase/android/appskeleton/permission/PermissionManager.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.qase.android.appskeleton.permission - -import android.app.Activity -import android.content.Context -import android.content.pm.PackageManager -import android.support.v4.app.ActivityCompat -import android.support.v4.content.ContextCompat - -class PermissionManager(context: Context, requiredPermissions: List) { - private val globalRequestCode = 100 - var permissionMap: HashMap = HashMap() - var listeners: MutableSet = mutableSetOf() - - init { - for (requiredPermission in requiredPermissions) { - if (ContextCompat.checkSelfPermission(context, requiredPermission) - != PackageManager.PERMISSION_GRANTED) { - permissionMap[requiredPermission] = PackageManager.PERMISSION_DENIED - } else { - permissionMap[requiredPermission] = PackageManager.PERMISSION_GRANTED - } - } - } - - fun registerListener(listener: IPermissionManagerListener) { - listeners.add(listener) - } - - fun unRegisterListener(listener: IPermissionManagerListener) { - listeners.remove(listener) - } - - /** - * Request all defined permissions - */ - fun requestAllPermissions(activity: Activity) { - val permissionRequestList = arrayListOf() - val keys = permissionMap.keys - keys.forEach { permission -> - // Here, thisActivity is the current activity - if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) { - // Permission is not granted - // Should we show an explanation? - if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { - // Show an explanation to the user *asynchronously* -- don't block - // this thread waiting for the user's response! After the user - // sees the explanation, try again to request the permission. - } else { - // No explanation needed, we can request the permission. - permissionRequestList.add(permission) - } - } else { - // Permission has already been granted - permissionMap[permission] = PackageManager.PERMISSION_GRANTED - } - } - requestPermissions(activity, permissionRequestList.toTypedArray()) - } - - /** - * Callback with permission results - * @NOTE unfortunately this must be called directly from overriden method in Activity - * @param requestCode Code used to pair with request - * @param permissions Array of requested permissions - * @param grantResults Array of results represented by integers - */ - fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { - if (requestCode == globalRequestCode) { - permissions.forEachIndexed { index, permission -> - val result = grantResults[index] - permissionMap[permission] = result - if (result == PackageManager.PERMISSION_GRANTED) { - for (listener in listeners) { - listener.onPermissionGranted(permission) - } - } else { - for (listener in listeners) { - listener.onPermissionDenied(permission) - } - } - } - } - } - - /** - * Initiate permission request - * @param permission Array of permissions to request - */ - fun requestPermissions(activity: Activity, permissions: Array) { - if (permissions.count() > 0) { - ActivityCompat.requestPermissions(activity, permissions, globalRequestCode) - } - } - - /** - * Check single permission - * @param permission String of permission - * @return True if permission is granted - */ - fun checkPermission(permission: String): Boolean { - val desiredPermission = permissionMap.get(permission) - return desiredPermission != null && desiredPermission == PackageManager.PERMISSION_GRANTED - } - - /** - * Check multiple permissions - * @param permissions Array of permission strings - * @return True if all permissions are granted - */ - fun checkPermissions(permissions: Array): Boolean { - return permissions.all { checkPermission(it) } - } -} \ No newline at end of file diff --git a/skeleton/src/main/res/layout/activity_main.xml b/skeleton/src/main/res/layout/activity_main.xml index a320675..aece932 100644 --- a/skeleton/src/main/res/layout/activity_main.xml +++ b/skeleton/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ - - - + diff --git a/skeleton/src/main/res/layout/main_layout.xml b/skeleton/src/main/res/layout/main_layout.xml index b08c1ba..7843da1 100644 --- a/skeleton/src/main/res/layout/main_layout.xml +++ b/skeleton/src/main/res/layout/main_layout.xml @@ -1,25 +1,24 @@ - - - - + - + diff --git a/skeleton/src/main/res/values/values.xml b/skeleton/src/main/res/values/values.xml index c267088..3f253d6 100644 --- a/skeleton/src/main/res/values/values.xml +++ b/skeleton/src/main/res/values/values.xml @@ -1,4 +1,4 @@ - android.support.design.widget.AppBarLayout$ScrollingViewBehavior + com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior \ No newline at end of file From 21f509e08182c0b7bc4c1531f7ba37d2550cd79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Wed, 6 Nov 2019 14:39:03 +0100 Subject: [PATCH 2/6] REF: migrate to androidx --- demo/build.gradle | 2 +- gradle.properties | 2 ++ skeleton/build.gradle | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index aea7d1e..922e7e4 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -11,7 +11,7 @@ android { targetSdkVersion 28 versionCode 1 versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { diff --git a/gradle.properties b/gradle.properties index aac7c9b..9e6fce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,8 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/skeleton/build.gradle b/skeleton/build.gradle index 3380cb4..8c98d62 100644 --- a/skeleton/build.gradle +++ b/skeleton/build.gradle @@ -12,7 +12,7 @@ android { versionCode 1 versionName "0.2.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } From 514c689afab05864968f0ed64b709e689afba323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Wed, 13 Nov 2019 13:03:05 +0100 Subject: [PATCH 3/6] REF: version 0.3.0 --- skeleton/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skeleton/build.gradle b/skeleton/build.gradle index 8c98d62..e49eba4 100644 --- a/skeleton/build.gradle +++ b/skeleton/build.gradle @@ -10,7 +10,7 @@ android { minSdkVersion 16 targetSdkVersion 28 versionCode 1 - versionName "0.2.0" + versionName "0.3.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" From 155e0351351a837b76de64cd89a79a097726528d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Wed, 13 Nov 2019 14:21:30 +0100 Subject: [PATCH 4/6] REF: update libraries --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- skeleton/build.gradle | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 5394b4c..84852e5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.50' ext.architecture_components_version = '1.1.1' repositories { google() @@ -9,7 +9,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:3.5.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 34a3fb9..ac4638d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Jun 20 15:05:12 CEST 2019 +#Wed Nov 13 14:18:46 CET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip diff --git a/skeleton/build.gradle b/skeleton/build.gradle index e49eba4..4f3f673 100644 --- a/skeleton/build.gradle +++ b/skeleton/build.gradle @@ -45,24 +45,24 @@ dependencies { // implementation 'com.android.support:preference-v7:27.1.1' // implementation 'com.android.support:design:27.1.1' - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.core:core-ktx:1.0.2' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha06' - implementation 'com.google.android.material:material:1.1.0-alpha07' - implementation 'androidx.fragment:fragment:1.1.0-beta01' - implementation 'androidx.preference:preference:1.1.0-beta01' + implementation 'androidx.recyclerview:recyclerview:1.1.0-rc01' + implementation 'com.google.android.material:material:1.2.0-alpha01' + implementation 'androidx.fragment:fragment:1.2.0-rc01' + implementation 'androidx.preference:preference:1.1.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // Architecture Components - implementation "androidx.lifecycle:lifecycle-runtime:2.2.0-alpha01" - implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01" - kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-alpha01" + implementation "androidx.lifecycle:lifecycle-runtime:2.2.0-rc02" + implementation "androidx.lifecycle:lifecycle-extensions:2.2.0-rc02" + kapt "androidx.lifecycle:lifecycle-compiler:2.2.0-rc02" //RxJava implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' - implementation 'io.reactivex.rxjava2:rxjava:2.2.8' + implementation 'io.reactivex.rxjava2:rxjava:2.2.10' } repositories { From 1f8de394b6ea4d75f1234e8f0ac86d9913f937bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Wed, 13 Nov 2019 15:32:02 +0100 Subject: [PATCH 5/6] REF: update travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 020d714..e997315 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: android android: components: - - build-tools-27.0.3 - - android-27 + - build-tools-28.0.3 + - android-28 licenses: - android-sdk-preview-license-.+ - android-sdk-license-.+ From dc167e3243aaf4532183eda5e6acf82220e8e121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Bal=C3=A1k?= Date: Wed, 13 Nov 2019 15:52:19 +0100 Subject: [PATCH 6/6] REF: update after migration to api 28 --- demo/build.gradle | 4 ---- .../appskeletondemo/main/testdagger/TestDaggerFragment.kt | 2 +- .../appskeletondemo/main/testviewmodel/TestvmFragment.kt | 2 +- skeleton/build.gradle | 4 ---- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 922e7e4..eb17bbc 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -21,10 +21,6 @@ android { } } -kapt { - generateStubs = true -} - dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" diff --git a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt index b5efdbb..c589d09 100644 --- a/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt +++ b/demo/src/main/java/com/qase/android/appskeletondemo/main/testdagger/TestDaggerFragment.kt @@ -20,7 +20,7 @@ class TestDaggerFragment : BaseViewModelFragment(Testvm override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) getDataButton.setOnClickListener{ viewModel.onGetDataClicked() } - viewModel.testLiveData.observe(this, Observer { + viewModel.testLiveData.observe(viewLifecycleOwner, Observer { textData.text = it?.toString() }) } diff --git a/skeleton/build.gradle b/skeleton/build.gradle index 4f3f673..ed066a6 100644 --- a/skeleton/build.gradle +++ b/skeleton/build.gradle @@ -28,10 +28,6 @@ android { } } -kapt { - generateStubs = true -} - dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])