Add update all button (no functionality yet)

This commit is contained in:
Dominik Schürmann 2014-04-27 22:22:21 +02:00
parent b3ca915459
commit d7203535e7
6 changed files with 154 additions and 0 deletions

View File

@ -240,5 +240,6 @@
<string name="requesting_root_access_body">Requesting root access…</string>
<string name="root_access_denied_title">Root access denied</string>
<string name="root_access_denied_body">Either your Android device is not rooted or you have denied root access for F-Droid.</string>
<string name="update_all">Update all</string>
</resources>

View File

@ -117,4 +117,9 @@ public class DefaultInstaller extends Installer {
}
}
@Override
public boolean supportsUnattendedOperations() {
return false;
}
}

View File

@ -211,4 +211,6 @@ abstract public class Installer {
}
public abstract boolean handleOnActivityResult(int requestCode, int resultCode, Intent data);
public abstract boolean supportsUnattendedOperations();
}

View File

@ -241,6 +241,11 @@ public class RootInstaller extends Installer {
});
}
@Override
public boolean supportsUnattendedOperations() {
return true;
}
/**
* pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] [--algo
* <algorithm name> --key <key-in-hex> --iv <IV-in-hex>] [--originating-uri

View File

@ -167,6 +167,11 @@ public class SystemPermissionInstaller extends Installer {
return false;
}
@Override
public boolean supportsUnattendedOperations() {
return false;
}
public final int INSTALL_REPLACE_EXISTING = 2;
/**

View File

@ -1,13 +1,39 @@
package org.fdroid.fdroid.views.fragments;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.installer.Installer;
import org.fdroid.fdroid.views.AppListAdapter;
import org.fdroid.fdroid.views.CanUpdateAppListAdapter;
public class CanUpdateAppsFragment extends AppListFragment {
// copied from ListFragment
static final int INTERNAL_EMPTY_ID = 0x00ff0001;
static final int INTERNAL_PROGRESS_CONTAINER_ID = 0x00ff0002;
static final int INTERNAL_LIST_CONTAINER_ID = 0x00ff0003;
// added for update button
static final int UPDATE_ALL_BUTTON_ID = 0x00ff0004;
private Button mUpdateAllButton;
private Installer mInstaller;
@Override
protected AppListAdapter getAppListAdapter() {
return new CanUpdateAppListAdapter(getActivity(), null);
@ -23,4 +49,114 @@ public class CanUpdateAppsFragment extends AppListFragment {
return AppProvider.getCanUpdateUri();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mInstaller = Installer.getActivityInstaller(getActivity(), getActivity()
.getPackageManager(), null);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mUpdateAllButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO
}
});
}
// TODO: not really called again after coming back from preference
@Override
public void onResume() {
super.onResume();
if (mInstaller.supportsUnattendedOperations()) {
mUpdateAllButton.setVisibility(View.VISIBLE);
} else {
mUpdateAllButton.setVisibility(View.GONE);
}
}
/**
* Copied from ListFragment and added EditText for search on top of list. We
* do not use a custom layout here, because this breaks the progress bar
* functionality of ListFragment.
*
* @param inflater
* @param container
* @param savedInstanceState
* @return
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context context = getActivity();
FrameLayout root = new FrameLayout(context);
// ------------------------------------------------------------------
LinearLayout pframe = new LinearLayout(context);
pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
pframe.setOrientation(LinearLayout.VERTICAL);
pframe.setVisibility(View.GONE);
pframe.setGravity(Gravity.CENTER);
ProgressBar progress = new ProgressBar(context, null,
android.R.attr.progressBarStyleLarge);
pframe.addView(progress, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
root.addView(pframe, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// ------------------------------------------------------------------
FrameLayout lframe = new FrameLayout(context);
lframe.setId(INTERNAL_LIST_CONTAINER_ID);
TextView tv = new TextView(getActivity());
tv.setId(INTERNAL_EMPTY_ID);
tv.setGravity(Gravity.CENTER);
lframe.addView(tv, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// Added update all button
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
mUpdateAllButton = new Button(context);
mUpdateAllButton.setId(UPDATE_ALL_BUTTON_ID);
mUpdateAllButton.setText(R.string.update_all);
mUpdateAllButton.setCompoundDrawablesWithIntrinsicBounds(
getResources().getDrawable(R.drawable.ic_menu_refresh), null, null, null);
linearLayout.addView(mUpdateAllButton, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
ListView lv = new ListView(getActivity());
lv.setId(android.R.id.list);
lv.setDrawSelectorOnTop(false);
linearLayout.addView(lv, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
lframe.addView(linearLayout, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
root.addView(lframe, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// ------------------------------------------------------------------
root.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
return root;
}
}