mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-02 17:56:56 +01:00
code cleanup
This commit is contained in:
parent
277b99b0c1
commit
9f4548c2e9
@ -2,8 +2,6 @@ package org.mariotaku.twidere.annotation;
|
||||
|
||||
import android.support.annotation.IntDef;
|
||||
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
|
@ -125,7 +125,7 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF
|
||||
ExtensionsListFragment::class.java)
|
||||
mEntriesAdapter!!.addPreference("refresh", R.drawable.ic_action_refresh, getString(R.string.refresh),
|
||||
R.xml.preferences_refresh)
|
||||
mEntriesAdapter!!.addPreference("notifications", R.drawable.ic_action_notification, getString(R.string.notifications),
|
||||
mEntriesAdapter!!.addPreference("notifications", R.drawable.ic_action_notification, getString(R.string.settings_notifications),
|
||||
R.xml.preferences_notifications)
|
||||
mEntriesAdapter!!.addPreference("network", R.drawable.ic_action_web, getString(R.string.network),
|
||||
R.xml.preferences_network)
|
||||
@ -220,8 +220,7 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF
|
||||
|
||||
protected fun openDetails(position: Int) {
|
||||
if (isFinishing) return
|
||||
val entry = mEntriesAdapter!!.getItem(position)
|
||||
if (entry !is PreferenceEntry) return
|
||||
val entry = mEntriesAdapter!!.getItem(position) as? PreferenceEntry ?: return
|
||||
val fm = supportFragmentManager
|
||||
fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
|
||||
val ft = fm.beginTransaction()
|
||||
|
@ -6,8 +6,6 @@ import android.app.AlertDialog
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.LoaderManager
|
||||
@ -37,10 +35,11 @@ import org.mariotaku.twidere.util.IntentUtils
|
||||
import org.mariotaku.twidere.util.Utils
|
||||
|
||||
/**
|
||||
* Sort and toggle account availability
|
||||
* Created by mariotaku on 14/10/26.
|
||||
*/
|
||||
class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallbacks<List<AccountDetails>>,
|
||||
OnSharedPreferenceChangeListener, AdapterView.OnItemClickListener {
|
||||
AdapterView.OnItemClickListener {
|
||||
|
||||
private var adapter: AccountDetailsAdapter? = null
|
||||
private var selectedAccount: AccountDetails? = null
|
||||
@ -49,7 +48,6 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
val activity = activity
|
||||
preferences.registerOnSharedPreferenceChangeListener(this)
|
||||
adapter = AccountDetailsAdapter(activity).apply {
|
||||
Utils.configBaseAdapter(activity, this)
|
||||
setSortEnabled(true)
|
||||
@ -63,7 +61,6 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
|
||||
listView.onItemClickListener = this
|
||||
listView.setDropListener { from, to ->
|
||||
adapter?.drop(from, to)
|
||||
// TODO sort list
|
||||
}
|
||||
listView.setOnCreateContextMenuListener(this)
|
||||
listView.emptyView = emptyView
|
||||
@ -138,11 +135,6 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
|
||||
saveAccountPositions()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
preferences.unregisterOnSharedPreferenceChangeListener(this)
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<AccountDetails>> {
|
||||
return AccountDetailsLoader(context)
|
||||
}
|
||||
@ -195,16 +187,6 @@ class AccountsManagerFragment : BaseSupportFragment(), LoaderManager.LoaderCallb
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(preferences: SharedPreferences, key: String) {
|
||||
if (SharedPreferenceConstants.KEY_DEFAULT_ACCOUNT_KEY == key) {
|
||||
updateDefaultAccount()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDefaultAccount() {
|
||||
adapter!!.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
class AccountDeletionDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener {
|
||||
|
||||
override fun onClick(dialog: DialogInterface, which: Int) {
|
||||
|
@ -21,8 +21,10 @@ import org.mariotaku.twidere.util.support.AccountManagerSupport
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Migrate legacy credentials to system account framework
|
||||
* Created by mariotaku on 2016/12/3.
|
||||
*/
|
||||
@Suppress("deprecation")
|
||||
fun migrateAccounts(am: AccountManager, db: SQLiteDatabase) {
|
||||
am.getAccountsByType(ACCOUNT_TYPE).map { account ->
|
||||
AccountManagerSupport.removeAccount(am, account, null, null, null)
|
||||
@ -54,7 +56,39 @@ fun migrateAccounts(am: AccountManager, db: SQLiteDatabase) {
|
||||
|
||||
fun toHexColor(@ColorInt color: Int) = String.format(Locale.ROOT, "#%6X", color)
|
||||
|
||||
@Suppress("deprecation")
|
||||
private fun ParcelableCredentials.toCredentials(): Credentials {
|
||||
|
||||
fun ParcelableCredentials.applyCommonProperties(credentials: Credentials) {
|
||||
credentials.api_url_format = api_url_format
|
||||
credentials.no_version_suffix = no_version_suffix
|
||||
}
|
||||
|
||||
fun ParcelableCredentials.toOAuthCredentials(): OAuthCredentials {
|
||||
val result = OAuthCredentials()
|
||||
applyCommonProperties(result)
|
||||
result.consumer_key = consumer_key
|
||||
result.consumer_secret = consumer_secret
|
||||
result.access_token = oauth_token
|
||||
result.access_token_secret = oauth_token_secret
|
||||
result.same_oauth_signing_url = same_oauth_signing_url
|
||||
return result
|
||||
}
|
||||
|
||||
fun ParcelableCredentials.toBasicCredentials(): BasicCredentials {
|
||||
val result = BasicCredentials()
|
||||
applyCommonProperties(result)
|
||||
result.username = basic_auth_username
|
||||
result.password = basic_auth_password
|
||||
return result
|
||||
}
|
||||
|
||||
fun ParcelableCredentials.toEmptyCredentials(): EmptyCredentials {
|
||||
val result = EmptyCredentials()
|
||||
applyCommonProperties(result)
|
||||
return result
|
||||
}
|
||||
|
||||
when (auth_type) {
|
||||
AuthTypeInt.OAUTH, AuthTypeInt.XAUTH -> return toOAuthCredentials()
|
||||
AuthTypeInt.BASIC -> return toBasicCredentials()
|
||||
@ -64,40 +98,11 @@ private fun ParcelableCredentials.toCredentials(): Credentials {
|
||||
}
|
||||
|
||||
@Credentials.Type
|
||||
@Suppress("deprecation")
|
||||
private fun ParcelableCredentials.getCredentialsType(): String {
|
||||
return AccountUtils.getCredentialsType(auth_type)
|
||||
}
|
||||
|
||||
|
||||
private fun ParcelableCredentials.toOAuthCredentials(): OAuthCredentials {
|
||||
val result = OAuthCredentials()
|
||||
applyCommonProperties(result)
|
||||
result.consumer_key = consumer_key
|
||||
result.consumer_secret = consumer_secret
|
||||
result.access_token = oauth_token
|
||||
result.access_token_secret = oauth_token_secret
|
||||
result.same_oauth_signing_url = same_oauth_signing_url
|
||||
return result
|
||||
}
|
||||
|
||||
private fun ParcelableCredentials.toBasicCredentials(): BasicCredentials {
|
||||
val result = BasicCredentials()
|
||||
applyCommonProperties(result)
|
||||
result.username = basic_auth_username
|
||||
result.password = basic_auth_password
|
||||
return result
|
||||
}
|
||||
|
||||
private fun ParcelableCredentials.toEmptyCredentials(): EmptyCredentials {
|
||||
val result = EmptyCredentials()
|
||||
applyCommonProperties(result)
|
||||
return result
|
||||
}
|
||||
|
||||
private fun ParcelableCredentials.applyCommonProperties(credentials: Credentials) {
|
||||
credentials.api_url_format = api_url_format
|
||||
credentials.no_version_suffix = no_version_suffix
|
||||
}
|
||||
|
||||
@Suppress("deprecation")
|
||||
private val ParcelableCredentials.account_name: String
|
||||
get() = UserKey(screen_name, account_key.host).toString()
|
||||
|
@ -116,6 +116,7 @@
|
||||
<string name="likes">Likes</string>
|
||||
<string name="name">Name</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
<string name="settings_refresh">Refresh</string>
|
||||
<string name="retry">Retry</string>
|
||||
<string name="more">More</string>
|
||||
<string name="quote_format">Quote format</string>
|
||||
@ -159,6 +160,7 @@
|
||||
<string name="ringtone">Ringtone</string>
|
||||
<string name="vibration">Vibration</string>
|
||||
<string name="light">Light</string>
|
||||
<string name="settings_notifications">Notifications</string>
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="refresh_on_start">Refresh on start</string>
|
||||
<string name="refresh_on_start_summary">Refresh timeline and mentions on start.</string>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/notifications">
|
||||
android:title="@string/settings_notifications">
|
||||
|
||||
<org.mariotaku.twidere.preference.NotificationAccountsListPreference
|
||||
android:key="cat_accounts"
|
||||
|
Loading…
x
Reference in New Issue
Block a user