code cleanup
This commit is contained in:
parent
fb7c30bda1
commit
8623368292
|
@ -31,7 +31,7 @@ import android.support.annotation.NonNull;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
import android.support.v4.content.AsyncTaskLoader;
|
||||
import android.support.v4.content.FixedAsyncTaskLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -262,7 +262,7 @@ public class FileSelectorDialogFragment extends BaseDialogFragment implements Lo
|
|||
|
||||
}
|
||||
|
||||
private static class FilesLoader extends AsyncTaskLoader<List<File>> {
|
||||
private static class FilesLoader extends FixedAsyncTaskLoader<List<File>> {
|
||||
|
||||
private final File path;
|
||||
private final String[] extensions;
|
||||
|
|
|
@ -1,207 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.loader;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.AsyncTaskLoader;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ExtensionsListLoader extends AsyncTaskLoader<List<ExtensionsListLoader.ExtensionInfo>>
|
||||
implements Constants {
|
||||
|
||||
private PackageIntentReceiver mPackageObserver;
|
||||
private final InterestingConfigChanges mLastConfig = new InterestingConfigChanges();
|
||||
private final PackageManager mPackageManager;
|
||||
|
||||
public ExtensionsListLoader(final Context context, final PackageManager pm) {
|
||||
super(context);
|
||||
mPackageManager = pm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExtensionInfo> loadInBackground() {
|
||||
final List<ApplicationInfo> apps = mPackageManager.getInstalledApplications(PackageManager.GET_META_DATA);
|
||||
final List<ExtensionInfo> extensions = new ArrayList<>();
|
||||
for (final ApplicationInfo info : apps) {
|
||||
final Bundle meta = info.metaData;
|
||||
if (meta != null && meta.getBoolean(METADATA_KEY_EXTENSION, false)) {
|
||||
extensions.add(new ExtensionInfo(info, mPackageManager));
|
||||
}
|
||||
}
|
||||
return extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to completely reset the Loader.
|
||||
*/
|
||||
@Override
|
||||
protected void onReset() {
|
||||
super.onReset();
|
||||
|
||||
// Ensure the loader is stopped
|
||||
onStopLoading();
|
||||
|
||||
// Stop monitoring for changes.
|
||||
if (mPackageObserver != null) {
|
||||
getContext().unregisterReceiver(mPackageObserver);
|
||||
mPackageObserver = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to start the Loader.
|
||||
*/
|
||||
@Override
|
||||
protected void onStartLoading() {
|
||||
|
||||
// Start watching for changes in the app data.
|
||||
if (mPackageObserver == null) {
|
||||
mPackageObserver = new PackageIntentReceiver(this);
|
||||
}
|
||||
|
||||
// Has something interesting in the configuration changed since we
|
||||
// last built the app list?
|
||||
final boolean configChange = mLastConfig.applyNewConfig(getContext().getResources());
|
||||
|
||||
if (takeContentChanged() || configChange) {
|
||||
// If the data has changed since the last time it was loaded
|
||||
// or is not currently available, start a load.
|
||||
forceLoad();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to stop the Loader.
|
||||
*/
|
||||
@Override
|
||||
protected void onStopLoading() {
|
||||
// Attempt to cancel the current load task if possible.
|
||||
cancelLoad();
|
||||
}
|
||||
|
||||
public static class ExtensionInfo implements Comparable<ExtensionInfo> {
|
||||
@Nullable
|
||||
public final String[] permissions;
|
||||
public final String label, description;
|
||||
public final String pname, settings;
|
||||
public final Drawable icon;
|
||||
|
||||
ExtensionInfo(final ApplicationInfo info, final PackageManager pm) {
|
||||
final Bundle meta = info.metaData;
|
||||
final String permissionString = meta.getString(METADATA_KEY_EXTENSION_PERMISSIONS);
|
||||
permissions = permissionString != null ? permissionString
|
||||
.split(SEPARATOR_PERMISSION_REGEX) : null;
|
||||
settings = meta.getString(METADATA_KEY_EXTENSION_SETTINGS);
|
||||
icon = info.loadIcon(pm);
|
||||
pname = info.packageName;
|
||||
label = ParseUtils.parseString(info.loadLabel(pm), pname);
|
||||
description = ParseUtils.parseString(info.loadDescription(pm));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull final ExtensionInfo another) {
|
||||
return label.compareToIgnoreCase(another.label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ExtensionInfo{" +
|
||||
"permissions=" + Arrays.toString(permissions) +
|
||||
", label='" + label + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", pname='" + pname + '\'' +
|
||||
", settings='" + settings + '\'' +
|
||||
", icon=" + icon +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for determining if the configuration has changed in an interesting
|
||||
* way so we need to rebuild the app list.
|
||||
*/
|
||||
public static class InterestingConfigChanges {
|
||||
|
||||
final Configuration mLastConfiguration = new Configuration();
|
||||
int mLastDensity;
|
||||
|
||||
boolean applyNewConfig(final Resources res) {
|
||||
final int configChanges = mLastConfiguration.updateFrom(res.getConfiguration());
|
||||
final boolean densityChanged = mLastDensity != res.getDisplayMetrics().densityDpi;
|
||||
if (densityChanged
|
||||
|| (configChanges & (ActivityInfo.CONFIG_LOCALE | ActivityInfo.CONFIG_UI_MODE | ActivityInfo.CONFIG_SCREEN_LAYOUT)) != 0) {
|
||||
mLastDensity = res.getDisplayMetrics().densityDpi;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to look for interesting changes to the installed apps so
|
||||
* that the loader can be updated.
|
||||
*/
|
||||
public static class PackageIntentReceiver extends BroadcastReceiver {
|
||||
|
||||
final ExtensionsListLoader mLoader;
|
||||
|
||||
public PackageIntentReceiver(final ExtensionsListLoader loader) {
|
||||
mLoader = loader;
|
||||
final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
||||
filter.addDataScheme("package");
|
||||
mLoader.getContext().registerReceiver(this, filter);
|
||||
// Register for events related to sdcard installation.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
|
||||
final IntentFilter sdFilter = new IntentFilter();
|
||||
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
|
||||
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
|
||||
mLoader.getContext().registerReceiver(this, sdFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
// Tell the loader about the change.
|
||||
mLoader.onContentChanged();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -23,7 +23,7 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.AsyncTaskLoader;
|
||||
import android.support.v4.content.FixedAsyncTaskLoader;
|
||||
import android.support.v4.content.LoaderAccessor;
|
||||
|
||||
import org.mariotaku.library.objectcursor.ObjectCursor;
|
||||
|
@ -37,7 +37,7 @@ import java.util.List;
|
|||
/**
|
||||
* Created by mariotaku on 15-7-5.
|
||||
*/
|
||||
public class ObjectCursorLoader<T> extends AsyncTaskLoader<List<T>> {
|
||||
public class ObjectCursorLoader<T> extends FixedAsyncTaskLoader<List<T>> {
|
||||
|
||||
final ForceLoadContentObserver mObserver;
|
||||
final Class<? extends ObjectCursor.CursorIndices<T>> mIndicesClass;
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.content.Context
|
|||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.LoaderManager
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.support.v4.content.Loader
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
|
@ -186,7 +186,7 @@ class APIEditorDialogFragment : BaseDialogFragment() {
|
|||
|
||||
}
|
||||
|
||||
class DefaultAPIConfigLoader(context: Context) : AsyncTaskLoader<List<CustomAPIConfig>?>(context) {
|
||||
class DefaultAPIConfigLoader(context: Context) : FixedAsyncTaskLoader<List<CustomAPIConfig>?>(context) {
|
||||
@Inject
|
||||
lateinit var client: RestHttpClient
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class ExtensionsListFragment : AbsContentListViewFragment<ExtensionsAdapter>(),
|
|||
}
|
||||
|
||||
override fun onCreateLoader(id: Int, args: Bundle?): Loader<List<ExtensionInfo>> {
|
||||
return ExtensionsListLoader(activity, packageManager)
|
||||
return ExtensionsListLoader(activity)
|
||||
}
|
||||
|
||||
override fun onLoadFinished(loader: Loader<List<ExtensionInfo>>, data: List<ExtensionInfo>) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.nfc.NdefRecord
|
|||
import android.nfc.NfcAdapter
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.support.v4.content.Loader
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.statusnet.model.Group
|
||||
|
@ -97,7 +97,7 @@ class GroupFragment : AbsToolbarTabPagesFragment(), LoaderCallbacks<SingleRespon
|
|||
private val accountKey: UserKey,
|
||||
private val groupId: String?,
|
||||
private val groupName: String?
|
||||
) : AsyncTaskLoader<SingleResponse<ParcelableGroup>>(context) {
|
||||
) : FixedAsyncTaskLoader<SingleResponse<ParcelableGroup>>(context) {
|
||||
|
||||
override fun loadInBackground(): SingleResponse<ParcelableGroup> {
|
||||
if (!omitIntentExtra && extras != null) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.support.v4.content.Loader
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.ContextMenu
|
||||
|
@ -155,7 +155,7 @@ class ItemsListFragment : AbsContentListRecyclerViewFragment<VariousItemsAdapter
|
|||
return false
|
||||
}
|
||||
|
||||
class ItemsLoader(context: Context, private val arguments: Bundle) : AsyncTaskLoader<List<*>>(context) {
|
||||
class ItemsLoader(context: Context, private val arguments: Bundle) : FixedAsyncTaskLoader<List<*>>(context) {
|
||||
|
||||
override fun loadInBackground(): List<*> {
|
||||
return arguments.getParcelableArrayList<Parcelable>(EXTRA_ITEMS)
|
||||
|
|
|
@ -35,6 +35,7 @@ import android.support.v4.app.LoaderManager.LoaderCallbacks
|
|||
import android.support.v4.app.hasRunningLoadersSafe
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.support.v4.content.Loader
|
||||
import android.support.v4.view.MenuItemCompat
|
||||
import android.support.v4.view.ViewCompat
|
||||
|
@ -2103,7 +2104,7 @@ class StatusFragment : BaseFragment(), LoaderCallbacks<SingleResponse<Parcelable
|
|||
context: Context,
|
||||
private val accountKey: UserKey,
|
||||
private val statusId: String
|
||||
) : AsyncTaskLoader<StatusActivity>(context) {
|
||||
) : FixedAsyncTaskLoader<StatusActivity>(context) {
|
||||
|
||||
override fun loadInBackground(): StatusActivity? {
|
||||
val context = context
|
||||
|
|
|
@ -46,6 +46,7 @@ import android.support.v4.app.Fragment
|
|||
import android.support.v4.app.FragmentActivity
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.support.v4.content.Loader
|
||||
import android.support.v4.content.res.ResourcesCompat
|
||||
import android.support.v4.graphics.ColorUtils
|
||||
|
@ -1560,7 +1561,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||
context: Context,
|
||||
private val accountKey: UserKey?,
|
||||
private val user: ParcelableUser?
|
||||
) : AsyncTaskLoader<SingleResponse<ParcelableRelationship>>(context) {
|
||||
) : FixedAsyncTaskLoader<SingleResponse<ParcelableRelationship>>(context) {
|
||||
|
||||
override fun loadInBackground(): SingleResponse<ParcelableRelationship> {
|
||||
if (accountKey == null || user == null) {
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.nfc.NfcAdapter.CreateNdefMessageCallback
|
|||
import android.os.Bundle
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.support.v4.content.Loader
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.text.TextUtils
|
||||
|
@ -409,7 +410,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, LoaderCa
|
|||
private val listName: String?,
|
||||
private val userKey: UserKey?,
|
||||
private val screenName: String?
|
||||
) : AsyncTaskLoader<SingleResponse<ParcelableUserList>>(context) {
|
||||
) : FixedAsyncTaskLoader<SingleResponse<ParcelableUserList>>(context) {
|
||||
|
||||
override fun loadInBackground(): SingleResponse<ParcelableUserList> {
|
||||
if (!omitIntentExtra && extras != null) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.mariotaku.twidere.loader
|
|||
import android.accounts.AccountManager
|
||||
import android.accounts.OnAccountsUpdateListener
|
||||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
|
||||
import org.mariotaku.ktextension.removeOnAccountsUpdatedListenerSafe
|
||||
import org.mariotaku.twidere.model.AccountDetails
|
||||
|
@ -15,7 +15,7 @@ import org.mariotaku.twidere.model.util.AccountUtils
|
|||
class AccountDetailsLoader(
|
||||
context: Context,
|
||||
val filter: (AccountDetails.() -> Boolean)? = null
|
||||
) : AsyncTaskLoader<List<AccountDetails>>(context) {
|
||||
) : FixedAsyncTaskLoader<List<AccountDetails>>(context) {
|
||||
private val am: AccountManager = AccountManager.get(context)
|
||||
private val accountUpdateListener = OnAccountsUpdateListener {
|
||||
onContentChanged()
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.statusnet.model.Group
|
||||
|
@ -42,7 +42,7 @@ abstract class BaseGroupsLoader(
|
|||
protected val accountKey: UserKey,
|
||||
override val cursor: Long,
|
||||
data: List<ParcelableGroup>?
|
||||
) : AsyncTaskLoader<List<ParcelableGroup>>(context), ICursorSupportLoader {
|
||||
) : FixedAsyncTaskLoader<List<ParcelableGroup>>(context), ICursorSupportLoader {
|
||||
|
||||
protected val data = NoDuplicatesArrayList<ParcelableGroup>()
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.util.Log
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
|
@ -48,7 +48,7 @@ abstract class BaseUserListsLoader(
|
|||
protected val accountId: UserKey,
|
||||
override val cursor: Long,
|
||||
data: List<ParcelableUserList>?
|
||||
) : AsyncTaskLoader<List<ParcelableUserList>>(context), ICursorSupportLoader {
|
||||
) : FixedAsyncTaskLoader<List<ParcelableUserList>>(context), ICursorSupportLoader {
|
||||
@Inject
|
||||
lateinit var preferences: SharedPreferencesWrapper
|
||||
|
||||
|
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import org.mariotaku.twidere.TwidereConstants.*
|
||||
import org.mariotaku.twidere.util.ParseUtils
|
||||
import java.util.*
|
||||
|
||||
class ExtensionsListLoader(
|
||||
context: Context
|
||||
) : FixedAsyncTaskLoader<List<ExtensionsListLoader.ExtensionInfo>>(context) {
|
||||
|
||||
private val packageManager = context.packageManager
|
||||
private var packageObserver: PackageIntentReceiver? = null
|
||||
private val lastConfig = InterestingConfigChanges()
|
||||
|
||||
override fun loadInBackground(): List<ExtensionInfo> {
|
||||
val apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
|
||||
val extensions = ArrayList<ExtensionInfo>()
|
||||
for (info in apps) {
|
||||
val meta = info.metaData
|
||||
if (meta != null && meta.getBoolean(METADATA_KEY_EXTENSION, false)) {
|
||||
extensions.add(ExtensionInfo(info, packageManager))
|
||||
}
|
||||
}
|
||||
return extensions
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to completely reset the Loader.
|
||||
*/
|
||||
override fun onReset() {
|
||||
super.onReset()
|
||||
|
||||
// Ensure the loader is stopped
|
||||
onStopLoading()
|
||||
|
||||
// Stop monitoring for changes.
|
||||
if (packageObserver != null) {
|
||||
context.unregisterReceiver(packageObserver)
|
||||
packageObserver = null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to start the Loader.
|
||||
*/
|
||||
override fun onStartLoading() {
|
||||
|
||||
// Start watching for changes in the app data.
|
||||
if (packageObserver == null) {
|
||||
packageObserver = PackageIntentReceiver(this)
|
||||
}
|
||||
|
||||
// Has something interesting in the configuration changed since we
|
||||
// last built the app list?
|
||||
val configChange = lastConfig.applyNewConfig(context.resources)
|
||||
|
||||
if (takeContentChanged() || configChange) {
|
||||
// If the data has changed since the last time it was loaded
|
||||
// or is not currently available, start a load.
|
||||
forceLoad()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a request to stop the Loader.
|
||||
*/
|
||||
override fun onStopLoading() {
|
||||
// Attempt to cancel the current load task if possible.
|
||||
cancelLoad()
|
||||
}
|
||||
|
||||
class ExtensionInfo(info: ApplicationInfo, pm: PackageManager) : Comparable<ExtensionInfo> {
|
||||
val permissions: Array<String>?
|
||||
val label: String
|
||||
val description: String
|
||||
val pname: String
|
||||
val settings: String
|
||||
val icon: Drawable
|
||||
|
||||
init {
|
||||
val meta = info.metaData
|
||||
val permissionString = meta.getString(METADATA_KEY_EXTENSION_PERMISSIONS)
|
||||
permissions = permissionString?.split('|')?.filterNot(String::isEmpty)?.toTypedArray()
|
||||
settings = meta.getString(METADATA_KEY_EXTENSION_SETTINGS)
|
||||
icon = info.loadIcon(pm)
|
||||
pname = info.packageName
|
||||
label = ParseUtils.parseString(info.loadLabel(pm), pname)
|
||||
description = ParseUtils.parseString(info.loadDescription(pm))
|
||||
}
|
||||
|
||||
override fun compareTo(another: ExtensionInfo): Int {
|
||||
return label.compareTo(another.label, ignoreCase = true)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "ExtensionInfo{" +
|
||||
"permissions=" + Arrays.toString(permissions) +
|
||||
", label='" + label + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", pname='" + pname + '\'' +
|
||||
", settings='" + settings + '\'' +
|
||||
", icon=" + icon +
|
||||
'}'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for determining if the configuration has changed in an interesting
|
||||
* way so we need to rebuild the app list.
|
||||
*/
|
||||
class InterestingConfigChanges {
|
||||
|
||||
internal val mLastConfiguration = Configuration()
|
||||
internal var mLastDensity: Int = 0
|
||||
|
||||
internal fun applyNewConfig(res: Resources): Boolean {
|
||||
val configChanges = mLastConfiguration.updateFrom(res.configuration)
|
||||
val densityChanged = mLastDensity != res.displayMetrics.densityDpi
|
||||
if (densityChanged || configChanges and (ActivityInfo.CONFIG_LOCALE or ActivityInfo.CONFIG_UI_MODE or ActivityInfo.CONFIG_SCREEN_LAYOUT) != 0) {
|
||||
mLastDensity = res.displayMetrics.densityDpi
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class to look for interesting changes to the installed apps so
|
||||
* that the loader can be updated.
|
||||
*/
|
||||
class PackageIntentReceiver(internal val mLoader: ExtensionsListLoader) : BroadcastReceiver() {
|
||||
|
||||
init {
|
||||
val filter = IntentFilter(Intent.ACTION_PACKAGE_ADDED)
|
||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED)
|
||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED)
|
||||
filter.addDataScheme("package")
|
||||
mLoader.context.registerReceiver(this, filter)
|
||||
// Register for events related to sdcard installation.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
|
||||
val sdFilter = IntentFilter()
|
||||
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE)
|
||||
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)
|
||||
mLoader.context.registerReceiver(this, sdFilter)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
// Tell the loader about the change.
|
||||
mLoader.onContentChanged()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ package org.mariotaku.twidere.loader
|
|||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import org.mariotaku.ktextension.set
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.ErrorInfo
|
||||
|
@ -49,7 +49,7 @@ class ParcelableStatusLoader(
|
|||
private val extras: Bundle?,
|
||||
private val accountKey: UserKey?,
|
||||
private val statusId: String?
|
||||
) : AsyncTaskLoader<SingleResponse<ParcelableStatus>>(context) {
|
||||
) : FixedAsyncTaskLoader<SingleResponse<ParcelableStatus>>(context) {
|
||||
|
||||
@Inject
|
||||
internal lateinit var userColorNameManager: UserColorNameManager
|
||||
|
|
|
@ -20,10 +20,8 @@
|
|||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.text.TextUtils
|
||||
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.loader.iface.IExtendedLoader
|
||||
import org.mariotaku.twidere.model.ParcelableStatus
|
||||
import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList
|
||||
|
@ -33,7 +31,7 @@ abstract class ParcelableStatusesLoader(
|
|||
adapterData: List<ParcelableStatus>?,
|
||||
protected val tabPosition: Int,
|
||||
override var fromUser: Boolean
|
||||
) : AsyncTaskLoader<List<ParcelableStatus>>(context), Constants, IExtendedLoader {
|
||||
) : FixedAsyncTaskLoader<List<ParcelableStatus>>(context), IExtendedLoader {
|
||||
|
||||
protected val data = NoDuplicatesArrayList<ParcelableStatus>()
|
||||
protected val isFirstLoad: Boolean = adapterData == null
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.mariotaku.twidere.loader
|
|||
import android.accounts.AccountManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import org.mariotaku.abstask.library.TaskStarter
|
||||
|
@ -56,7 +56,7 @@ class ParcelableUserLoader(
|
|||
private val extras: Bundle?,
|
||||
private val omitIntentExtra: Boolean,
|
||||
private val loadFromCache: Boolean
|
||||
) : AsyncTaskLoader<SingleResponse<ParcelableUser>>(context), Constants {
|
||||
) : FixedAsyncTaskLoader<SingleResponse<ParcelableUser>>(context), Constants {
|
||||
|
||||
@Inject
|
||||
lateinit var userColorNameManager: UserColorNameManager
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.text.TextUtils
|
||||
import org.mariotaku.twidere.loader.iface.IExtendedLoader
|
||||
import org.mariotaku.twidere.model.ParcelableUser
|
||||
|
@ -31,7 +31,7 @@ abstract class ParcelableUsersLoader(
|
|||
context: Context,
|
||||
data: List<ParcelableUser>?,
|
||||
override var fromUser: Boolean
|
||||
) : AsyncTaskLoader<List<ParcelableUser>>(context), IExtendedLoader {
|
||||
) : FixedAsyncTaskLoader<List<ParcelableUser>>(context), IExtendedLoader {
|
||||
|
||||
protected val data: MutableList<ParcelableUser> = Collections.synchronizedList(NoDuplicatesArrayList<ParcelableUser>())
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
package org.mariotaku.twidere.loader
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.content.AsyncTaskLoader
|
||||
import android.support.v4.content.FixedAsyncTaskLoader
|
||||
import android.util.Log
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.ResponseList
|
||||
|
@ -33,11 +33,10 @@ import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
|||
class SavedSearchesLoader(
|
||||
context: Context,
|
||||
private val accountId: UserKey
|
||||
) : AsyncTaskLoader<ResponseList<SavedSearch>>(context), Constants {
|
||||
) : FixedAsyncTaskLoader<ResponseList<SavedSearch>>(context), Constants {
|
||||
|
||||
override fun loadInBackground(): ResponseList<SavedSearch>? {
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, accountId
|
||||
) ?: return null
|
||||
val twitter = MicroBlogAPIFactory.getInstance(context, accountId) ?: return null
|
||||
try {
|
||||
return twitter.savedSearches
|
||||
} catch (e: MicroBlogException) {
|
||||
|
|
Loading…
Reference in New Issue