Static import of inner class to improve readability
This commit is contained in:
parent
8bececfa58
commit
13e2eddb6a
@ -32,6 +32,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
|||||||
|
|
||||||
import org.fdroid.fdroid.AppDetails2;
|
import org.fdroid.fdroid.AppDetails2;
|
||||||
import org.fdroid.fdroid.AppUpdateStatusManager;
|
import org.fdroid.fdroid.AppUpdateStatusManager;
|
||||||
|
import org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.data.Apk;
|
import org.fdroid.fdroid.data.Apk;
|
||||||
@ -57,7 +58,7 @@ import java.util.Iterator;
|
|||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* The state of the UI is defined in a dumb {@link AppListItemState} class, then applied to the UI
|
* The state of the UI is defined in a dumb {@link AppListItemState} class, then applied to the UI
|
||||||
* in the {@link #refreshView(App, AppUpdateStatusManager.AppUpdateStatus)} method.
|
* in the {@link #refreshView(App, AppUpdateStatus)} method.
|
||||||
*/
|
*/
|
||||||
public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
@ -102,7 +103,7 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
|||||||
private App currentApp;
|
private App currentApp;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private AppUpdateStatusManager.AppUpdateStatus currentStatus;
|
private AppUpdateStatus currentStatus;
|
||||||
|
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
public AppListItemController(final Activity activity, View itemView) {
|
public AppListItemController(final Activity activity, View itemView) {
|
||||||
@ -166,10 +167,10 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
|||||||
|
|
||||||
// Figures out the current install/update/download/etc status for the app we are viewing.
|
// Figures out the current install/update/download/etc status for the app we are viewing.
|
||||||
// Then, asks the view to update itself to reflect this status.
|
// Then, asks the view to update itself to reflect this status.
|
||||||
Iterator<AppUpdateStatusManager.AppUpdateStatus> statuses =
|
Iterator<AppUpdateStatus> statuses =
|
||||||
AppUpdateStatusManager.getInstance(activity).getByPackageName(app.packageName).iterator();
|
AppUpdateStatusManager.getInstance(activity).getByPackageName(app.packageName).iterator();
|
||||||
if (statuses.hasNext()) {
|
if (statuses.hasNext()) {
|
||||||
AppUpdateStatusManager.AppUpdateStatus status = statuses.next();
|
AppUpdateStatus status = statuses.next();
|
||||||
updateAppStatus(app, status);
|
updateAppStatus(app, status);
|
||||||
} else {
|
} else {
|
||||||
updateAppStatus(app, null);
|
updateAppStatus(app, null);
|
||||||
@ -190,23 +191,22 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
|||||||
* Updates both the progress bar and the circular install button (which shows progress around the outside of
|
* Updates both the progress bar and the circular install button (which shows progress around the outside of
|
||||||
* the circle). Also updates the app label to indicate that the app is being downloaded.
|
* the circle). Also updates the app label to indicate that the app is being downloaded.
|
||||||
*/
|
*/
|
||||||
private void updateAppStatus(@NonNull App app, @Nullable AppUpdateStatusManager.AppUpdateStatus status) {
|
private void updateAppStatus(@NonNull App app, @Nullable AppUpdateStatus status) {
|
||||||
currentStatus = status;
|
currentStatus = status;
|
||||||
refreshView(app, status);
|
refreshView(app, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries the current state via {@link #getCurrentViewState(App, AppUpdateStatusManager.AppUpdateStatus)}
|
* Queries the current state via {@link #getCurrentViewState(App, AppUpdateStatus)}
|
||||||
* and then updates the relevant widgets depending on that state.
|
* and then updates the relevant widgets depending on that state.
|
||||||
*
|
*
|
||||||
* Should contain little to no business logic, this all belongs to
|
* Should contain little to no business logic, this all belongs to
|
||||||
* {@link #getCurrentViewState(App, AppUpdateStatusManager.AppUpdateStatus)}.
|
* {@link #getCurrentViewState(App, AppUpdateStatus)}.
|
||||||
*
|
*
|
||||||
* @see AppListItemState
|
* @see AppListItemState
|
||||||
* @see #getCurrentViewState(App, AppUpdateStatusManager.AppUpdateStatus)
|
* @see #getCurrentViewState(App, AppUpdateStatus)
|
||||||
*/
|
*/
|
||||||
private void refreshView(@NonNull App app,
|
private void refreshView(@NonNull App app, @Nullable AppUpdateStatus appStatus) {
|
||||||
@Nullable AppUpdateStatusManager.AppUpdateStatus appStatus) {
|
|
||||||
|
|
||||||
AppListItemState viewState = getCurrentViewState(app, appStatus);
|
AppListItemState viewState = getCurrentViewState(app, appStatus);
|
||||||
|
|
||||||
@ -292,8 +292,7 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected AppListItemState getCurrentViewState(
|
protected AppListItemState getCurrentViewState(@NonNull App app, @Nullable AppUpdateStatus appStatus) {
|
||||||
@NonNull App app, @Nullable AppUpdateStatusManager.AppUpdateStatus appStatus) {
|
|
||||||
if (appStatus == null) {
|
if (appStatus == null) {
|
||||||
return getViewStateDefault(app);
|
return getViewStateDefault(app);
|
||||||
} else {
|
} else {
|
||||||
@ -328,8 +327,7 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AppListItemState getViewStateDownloading(
|
protected AppListItemState getViewStateDownloading(@NonNull App app, @NonNull AppUpdateStatus currentStatus) {
|
||||||
@NonNull App app, @NonNull AppUpdateStatusManager.AppUpdateStatus currentStatus) {
|
|
||||||
CharSequence mainText = activity.getString(
|
CharSequence mainText = activity.getString(
|
||||||
R.string.app_list__name__downloading_in_progress, app.name);
|
R.string.app_list__name__downloading_in_progress, app.name);
|
||||||
|
|
||||||
@ -384,8 +382,7 @@ public abstract class AppListItemController extends RecyclerView.ViewHolder {
|
|||||||
private final BroadcastReceiver onStatusChanged = new BroadcastReceiver() {
|
private final BroadcastReceiver onStatusChanged = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
AppUpdateStatusManager.AppUpdateStatus newStatus =
|
AppUpdateStatus newStatus = intent.getParcelableExtra(AppUpdateStatusManager.EXTRA_STATUS);
|
||||||
intent.getParcelableExtra(AppUpdateStatusManager.EXTRA_STATUS);
|
|
||||||
|
|
||||||
if (currentApp == null
|
if (currentApp == null
|
||||||
|| !TextUtils.equals(newStatus.app.packageName, currentApp.packageName)
|
|| !TextUtils.equals(newStatus.app.packageName, currentApp.packageName)
|
||||||
|
@ -23,6 +23,7 @@ import com.ashokvarma.bottomnavigation.BottomNavigationItem;
|
|||||||
|
|
||||||
import org.fdroid.fdroid.AppDetails2;
|
import org.fdroid.fdroid.AppDetails2;
|
||||||
import org.fdroid.fdroid.AppUpdateStatusManager;
|
import org.fdroid.fdroid.AppUpdateStatusManager;
|
||||||
|
import org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus;
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.NfcHelper;
|
import org.fdroid.fdroid.NfcHelper;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
@ -385,8 +386,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have moved into the ReadyToInstall or Installed state.
|
// Check if we have moved into the ReadyToInstall or Installed state.
|
||||||
AppUpdateStatusManager.AppUpdateStatus status = manager.get(
|
AppUpdateStatus status = manager.get(intent.getStringExtra(AppUpdateStatusManager.EXTRA_APK_URL));
|
||||||
intent.getStringExtra(AppUpdateStatusManager.EXTRA_APK_URL));
|
|
||||||
boolean isStatusChange = intent.getBooleanExtra(AppUpdateStatusManager.EXTRA_IS_STATUS_UPDATE, false);
|
boolean isStatusChange = intent.getBooleanExtra(AppUpdateStatusManager.EXTRA_IS_STATUS_UPDATE, false);
|
||||||
if (isStatusChange
|
if (isStatusChange
|
||||||
&& status != null
|
&& status != null
|
||||||
@ -396,7 +396,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
|
|||||||
|
|
||||||
if (updateBadge) {
|
if (updateBadge) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (AppUpdateStatusManager.AppUpdateStatus s : manager.getAll()) {
|
for (AppUpdateStatus s : manager.getAll()) {
|
||||||
if (s.status == AppUpdateStatusManager.Status.ReadyToInstall) {
|
if (s.status == AppUpdateStatusManager.Status.ReadyToInstall) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import android.support.annotation.Nullable;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import org.fdroid.fdroid.AppUpdateStatusManager;
|
import org.fdroid.fdroid.AppUpdateStatusManager;
|
||||||
|
import org.fdroid.fdroid.AppUpdateStatusManager.AppUpdateStatus;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.data.App;
|
import org.fdroid.fdroid.data.App;
|
||||||
import org.fdroid.fdroid.views.apps.AppListItemController;
|
import org.fdroid.fdroid.views.apps.AppListItemController;
|
||||||
@ -24,15 +25,14 @@ public class AppStatusListItemController extends AppListItemController {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected AppListItemState getCurrentViewState(
|
protected AppListItemState getCurrentViewState(@NonNull App app, @Nullable AppUpdateStatus appStatus) {
|
||||||
@NonNull App app, @Nullable AppUpdateStatusManager.AppUpdateStatus appStatus) {
|
|
||||||
|
|
||||||
return super.getCurrentViewState(app, appStatus)
|
return super.getCurrentViewState(app, appStatus)
|
||||||
.setStatusText(getStatusText(appStatus));
|
.setStatusText(getStatusText(appStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private CharSequence getStatusText(@Nullable AppUpdateStatusManager.AppUpdateStatus appStatus) {
|
private CharSequence getStatusText(@Nullable AppUpdateStatus appStatus) {
|
||||||
if (appStatus != null) {
|
if (appStatus != null) {
|
||||||
switch (appStatus.status) {
|
switch (appStatus.status) {
|
||||||
case ReadyToInstall:
|
case ReadyToInstall:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user