adding auto refresh confirm

This commit is contained in:
Mariotaku Lee 2016-12-17 12:10:24 +08:00
parent 57b8070fdd
commit 861bab1c86
8 changed files with 56 additions and 17 deletions

View File

@ -309,6 +309,7 @@ public interface SharedPreferenceConstants {
String KEY_DRAWER_TOGGLE = "drawer_toggle"; String KEY_DRAWER_TOGGLE = "drawer_toggle";
String KEY_RANDOMIZE_ACCOUNT_NAME = "randomize_account_name"; String KEY_RANDOMIZE_ACCOUNT_NAME = "randomize_account_name";
String KEY_DEFAULT_AUTO_REFRESH = "default_auto_refresh";
String KEY_MEDIA_LINK_COUNTS_IN_STATUS = "media_link_counts_in_status"; String KEY_MEDIA_LINK_COUNTS_IN_STATUS = "media_link_counts_in_status";
String KEY_DROPBOX_ACCESS_TOKEN = "dropbox_access_token"; String KEY_DROPBOX_ACCESS_TOKEN = "dropbox_access_token";

View File

@ -176,7 +176,7 @@ dependencies {
compile "com.github.mariotaku.CommonsLibrary:io:$mariotaku_commons_library_version" compile "com.github.mariotaku.CommonsLibrary:io:$mariotaku_commons_library_version"
compile "com.github.mariotaku.CommonsLibrary:text:$mariotaku_commons_library_version" compile "com.github.mariotaku.CommonsLibrary:text:$mariotaku_commons_library_version"
compile "com.github.mariotaku.CommonsLibrary:text-kotlin:$mariotaku_commons_library_version" compile "com.github.mariotaku.CommonsLibrary:text-kotlin:$mariotaku_commons_library_version"
compile 'com.github.mariotaku:KPreferences:0.9.4' compile 'com.github.mariotaku:KPreferences:0.9.5'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'nl.komponents.kovenant:kovenant:3.3.0' compile 'nl.komponents.kovenant:kovenant:3.3.0'
compile 'nl.komponents.kovenant:kovenant-android:3.3.0' compile 'nl.komponents.kovenant:kovenant-android:3.3.0'

View File

@ -88,7 +88,7 @@ public class AccountPreferences implements Constants {
} }
public boolean isAutoRefreshEnabled() { public boolean isAutoRefreshEnabled() {
return mPreferences.getBoolean(KEY_AUTO_REFRESH, DEFAULT_AUTO_REFRESH); return mPreferences.getBoolean(KEY_AUTO_REFRESH, mPreferences.getBoolean(KEY_DEFAULT_AUTO_REFRESH, false));
} }
public boolean isAutoRefreshHomeTimelineEnabled() { public boolean isAutoRefreshHomeTimelineEnabled() {

View File

@ -22,6 +22,7 @@ package org.mariotaku.twidere.activity
import android.accounts.Account import android.accounts.Account
import android.accounts.AccountManager import android.accounts.AccountManager
import android.accounts.OnAccountsUpdateListener import android.accounts.OnAccountsUpdateListener
import android.app.Dialog
import android.app.PendingIntent import android.app.PendingIntent
import android.app.SearchManager import android.app.SearchManager
import android.content.Context import android.content.Context
@ -41,6 +42,7 @@ import android.support.v4.view.ViewPager.OnPageChangeListener
import android.support.v4.widget.DrawerLayout import android.support.v4.widget.DrawerLayout
import android.support.v4.widget.DrawerLayoutAccessor import android.support.v4.widget.DrawerLayoutAccessor
import android.support.v7.app.ActionBarDrawerToggle import android.support.v7.app.ActionBarDrawerToggle
import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatDelegate import android.support.v7.app.AppCompatDelegate
import android.support.v7.widget.TintTypedArray import android.support.v7.widget.TintTypedArray
import android.util.SparseIntArray import android.util.SparseIntArray
@ -72,6 +74,7 @@ import org.mariotaku.twidere.annotation.CustomTabType
import org.mariotaku.twidere.annotation.ReadPositionTag import org.mariotaku.twidere.annotation.ReadPositionTag
import org.mariotaku.twidere.constant.KeyboardShortcutConstants import org.mariotaku.twidere.constant.KeyboardShortcutConstants
import org.mariotaku.twidere.constant.SharedPreferenceConstants import org.mariotaku.twidere.constant.SharedPreferenceConstants
import org.mariotaku.twidere.constant.defaultAutoRefreshKeyAsked
import org.mariotaku.twidere.constant.drawerTutorialCompleted import org.mariotaku.twidere.constant.drawerTutorialCompleted
import org.mariotaku.twidere.fragment.* import org.mariotaku.twidere.fragment.*
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface
@ -311,6 +314,10 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
signInIntent.setClass(this, SignInActivity::class.java) signInIntent.setClass(this, SignInActivity::class.java)
startActivity(signInIntent) startActivity(signInIntent)
finish() finish()
if (defaultAutoRefreshKeyAsked !in kPreferences) {
// Assume first install
kPreferences[defaultAutoRefreshKeyAsked] = false
}
return return
} else { } else {
notifyAccountsChanged() notifyAccountsChanged()
@ -387,7 +394,9 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
startService(Intent(this, StreamingService::class.java)) startService(Intent(this, StreamingService::class.java))
} }
openDrawerTutorial() if (!showDrawerTutorial() && !kPreferences[defaultAutoRefreshKeyAsked]) {
showAutoRefreshConfirm()
}
} }
override fun onStart() { override fun onStart() {
@ -717,7 +726,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
homeMenu.openDrawer(GravityCompat.START) homeMenu.openDrawer(GravityCompat.START)
} }
private fun openDrawerTutorial(): Boolean { private fun showDrawerTutorial(): Boolean {
if (preferences[drawerTutorialCompleted]) return false if (preferences[drawerTutorialCompleted]) return false
val targetSize = resources.getDimensionPixelSize(R.dimen.element_size_mlarge) val targetSize = resources.getDimensionPixelSize(R.dimen.element_size_mlarge)
val height = resources.displayMetrics.heightPixels val height = resources.displayMetrics.heightPixels
@ -731,6 +740,8 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
override fun onTargetDismissed(view: TapTargetView?, userInitiated: Boolean) { override fun onTargetDismissed(view: TapTargetView?, userInitiated: Boolean) {
preferences[drawerTutorialCompleted] = true preferences[drawerTutorialCompleted] = true
showAutoRefreshConfirm()
} }
} }
val target = Rect(0, 0, targetSize, targetSize) val target = Rect(0, 0, targetSize, targetSize)
@ -746,6 +757,10 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
return true return true
} }
private fun showAutoRefreshConfirm() {
}
private fun setTabPosition(initialTab: Int) { private fun setTabPosition(initialTab: Int) {
val rememberPosition = preferences.getBoolean(SharedPreferenceConstants.KEY_REMEMBER_POSITION, true) val rememberPosition = preferences.getBoolean(SharedPreferenceConstants.KEY_REMEMBER_POSITION, true)
if (initialTab >= 0) { if (initialTab >= 0) {
@ -910,6 +925,21 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
internal class TabBadge(var index: Int, var count: Int) internal class TabBadge(var index: Int, var count: Int)
} }
class AutoRefreshConfirmDialogFragment : BaseDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(context)
builder.setTitle(R.string.auto_refresh)
builder.setMessage(R.string.message_auto_refresh_confirm)
builder.setPositiveButton(android.R.string.ok) { dialog, which ->
}
builder.setPositiveButton(R.string.no_thanks) { dialog, which ->
}
return builder.create()
}
}
companion object { companion object {
private val HOME_AS_UP_ATTRS = intArrayOf(android.support.v7.appcompat.R.attr.homeAsUpIndicator) private val HOME_AS_UP_ATTRS = intArrayOf(android.support.v7.appcompat.R.attr.homeAsUpIndicator)
} }

View File

@ -392,22 +392,26 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
Toast.makeText(this, R.string.error_already_logged_in, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.error_already_logged_in, Toast.LENGTH_SHORT).show()
} else { } else {
result.addAccount(am, preferences[randomizeAccountNameKey]) result.addAccount(am, preferences[randomizeAccountNameKey])
if (accountAuthenticatorResponse != null) {
accountAuthenticatorResult = Bundle {
this[AccountManager.KEY_BOOLEAN_RESULT] = true
}
} else {
val intent = Intent(this, HomeActivity::class.java)
//TODO refresh time lines
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
startActivity(intent)
}
Analyzer.log(SignIn(true, accountType = result.accountType.first, credentialsType = apiConfig.credentialsType, Analyzer.log(SignIn(true, accountType = result.accountType.first, credentialsType = apiConfig.credentialsType,
officialKey = result.accountType.second?.official ?: false)) officialKey = result.accountType.second?.official ?: false))
finish() finishSignIn()
} }
} }
private fun finishSignIn() {
if (accountAuthenticatorResponse != null) {
accountAuthenticatorResult = Bundle {
this[AccountManager.KEY_BOOLEAN_RESULT] = true
}
} else {
val intent = Intent(this, HomeActivity::class.java)
//TODO refresh time lines
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
startActivity(intent)
}
finish()
}
internal fun onSignInError(exception: Exception) { internal fun onSignInError(exception: Exception) {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Log.w(LOGTAG, exception) Log.w(LOGTAG, exception)

View File

@ -41,6 +41,8 @@ val apiLastChangeKey = KLongKey(KEY_API_LAST_CHANGE, -1)
val bugReportsKey = KBooleanKey(KEY_BUG_REPORTS, BuildConfig.DEBUG) val bugReportsKey = KBooleanKey(KEY_BUG_REPORTS, BuildConfig.DEBUG)
val readFromBottomKey = KBooleanKey(KEY_READ_FROM_BOTTOM, false) val readFromBottomKey = KBooleanKey(KEY_READ_FROM_BOTTOM, false)
val randomizeAccountNameKey = KBooleanKey(KEY_RANDOMIZE_ACCOUNT_NAME, false) val randomizeAccountNameKey = KBooleanKey(KEY_RANDOMIZE_ACCOUNT_NAME, false)
val defaultAutoRefreshKey = KBooleanKey(KEY_DEFAULT_AUTO_REFRESH, false)
val defaultAutoRefreshKeyAsked = KBooleanKey("default_auto_refresh_asked", true)
object defaultAPIConfigKey : KPreferenceKey<CustomAPIConfig> { object defaultAPIConfigKey : KPreferenceKey<CustomAPIConfig> {
override fun contains(preferences: SharedPreferences): Boolean { override fun contains(preferences: SharedPreferences): Boolean {

View File

@ -20,9 +20,10 @@
package org.mariotaku.twidere.fragment package org.mariotaku.twidere.fragment
import android.content.SharedPreferences import android.content.SharedPreferences
import org.mariotaku.kpreferences.get
import org.mariotaku.twidere.R import org.mariotaku.twidere.R
import org.mariotaku.twidere.constant.SharedPreferenceConstants.DEFAULT_AUTO_REFRESH
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_AUTO_REFRESH import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_AUTO_REFRESH
import org.mariotaku.twidere.constant.defaultAutoRefreshKey
import org.mariotaku.twidere.util.Utils import org.mariotaku.twidere.util.Utils
class AccountRefreshSettingsFragment : BaseAccountPreferenceFragment() { class AccountRefreshSettingsFragment : BaseAccountPreferenceFragment() {
@ -31,7 +32,7 @@ class AccountRefreshSettingsFragment : BaseAccountPreferenceFragment() {
get() = R.xml.preferences_account_refresh get() = R.xml.preferences_account_refresh
override val switchPreferenceDefault: Boolean override val switchPreferenceDefault: Boolean
get() = DEFAULT_AUTO_REFRESH get() = preferenceManager.sharedPreferences[defaultAutoRefreshKey]
override val switchPreferenceKey: String? override val switchPreferenceKey: String?
get() = KEY_AUTO_REFRESH get() = KEY_AUTO_REFRESH

View File

@ -817,4 +817,5 @@
<string name="preference_randomize_account_name">Randomize account name</string> <string name="preference_randomize_account_name">Randomize account name</string>
<string name="preference_randomize_account_name_summary">Disallow other apps to get your name by reading accounts, improves privacy.</string> <string name="preference_randomize_account_name_summary">Disallow other apps to get your name by reading accounts, improves privacy.</string>
<string name="preference_randomize_account_rename_accounts_confirm">Rename existing accounts?</string> <string name="preference_randomize_account_rename_accounts_confirm">Rename existing accounts?</string>
<string name="message_auto_refresh_confirm">Enable auto refresh to get new tweets automatically?</string>
</resources> </resources>