Added move dialog on start and list item buttons (move/delete).
This commit is contained in:
parent
90a1973853
commit
f7952aa9ce
6 changed files with 87 additions and 15 deletions
|
@ -13,8 +13,15 @@ android {
|
|||
testHandleProfiling true
|
||||
testFunctionalTest true
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
applicationIdSuffix ".debug"
|
||||
debuggable true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':libsuperuser')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
|
@ -12,8 +13,15 @@ import android.widget.TextView;
|
|||
*/
|
||||
public class CertificateAdapter extends ArrayAdapter<Certificate> {
|
||||
|
||||
public CertificateAdapter(Context context) {
|
||||
super(context, android.R.layout.simple_list_item_1);
|
||||
private CertificateManager mCertificateManager;
|
||||
|
||||
private MovedCertificatesStorage mMovedCertificatesStorage;
|
||||
|
||||
public CertificateAdapter(Context context, CertificateManager certificateManager,
|
||||
MovedCertificatesStorage movedCertificatesStorage) {
|
||||
super(context, 0);
|
||||
mCertificateManager = certificateManager;
|
||||
mMovedCertificatesStorage = movedCertificatesStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,15 +29,37 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> {
|
|||
if (convertView == null) {
|
||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||
convertView = inflater.inflate(R.layout.certificate_list_item, parent, false);
|
||||
}
|
||||
|
||||
TextView title = (TextView) convertView.findViewById(android.R.id.text1);
|
||||
title.setText(getItem(position).getFile().getName());
|
||||
convertView.setBackgroundColor(getContext().getResources().getColor(
|
||||
(getItem(position).isSystemCertificate())
|
||||
? R.color.background_system_certificate
|
||||
: R.color.background_user_certificate));
|
||||
final Certificate cert = getItem(position);
|
||||
TextView title = (TextView) convertView.findViewById(R.id.title);
|
||||
title.setText(cert.getFile().getName());
|
||||
Button button = (Button) convertView.findViewById(R.id.button);
|
||||
int colorRes;
|
||||
if (cert.isSystemCertificate()) {
|
||||
button.setText(R.string.delete);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mCertificateManager.deleteCertificate(cert);
|
||||
mMovedCertificatesStorage.delete(cert);
|
||||
}
|
||||
});
|
||||
colorRes = R.color.background_system_certificate;
|
||||
}
|
||||
else {
|
||||
button.setText(R.string.move_to_system);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mCertificateManager.moveCertificateToSystem(cert);
|
||||
mMovedCertificatesStorage.insert(cert);
|
||||
}
|
||||
});
|
||||
colorRes = R.color.background_user_certificate;
|
||||
}
|
||||
convertView.setBackgroundColor(getContext().getResources().getColor(colorRes));
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import android.widget.ListView;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MainActivity extends ListActivity {
|
||||
|
||||
private ListView mListView;
|
||||
|
@ -27,15 +26,21 @@ public class MainActivity extends ListActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
|
||||
mListView = getListView();
|
||||
mCertificateAdapter = new CertificateAdapter(this);
|
||||
mCertificateManager = new CertificateManager();
|
||||
mMovedCertificatesStorage = new MovedCertificatesStorage(this);
|
||||
mCertificateAdapter =
|
||||
new CertificateAdapter(this, mCertificateManager, mMovedCertificatesStorage);
|
||||
|
||||
mCertificateAdapter.addAll(mCertificateManager.getCertificates(false));
|
||||
// FIXME: nothing listed
|
||||
// -> db table is empty
|
||||
mCertificateAdapter.addAll(mMovedCertificatesStorage.list());
|
||||
mListView.setAdapter(mCertificateAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a dialog to move all user certificates to system storage.
|
||||
*/
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
@ -48,7 +53,7 @@ public class MainActivity extends ListActivity {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for (Certificate c : list) {
|
||||
mCertificateManager.moveCertificateToSystem(c);
|
||||
c = mCertificateManager.moveCertificateToSystem(c);
|
||||
mMovedCertificatesStorage.insert(c);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.provider.BaseColumns;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -32,8 +33,7 @@ public class MovedCertificatesStorage implements Closeable {
|
|||
}
|
||||
|
||||
public boolean insert(Certificate cert) {
|
||||
if (!cert.isSystemCertificate())
|
||||
return false;
|
||||
assert(cert.isSystemCertificate());
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(Table.COLUMN_NAME_FILE_NAME, cert.getFile().getName());
|
||||
|
|
26
app/src/main/res/layout/certificate_list_item.xml
Normal file
26
app/src/main/res/layout/certificate_list_item.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:mode="twoLine"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@id/title"
|
||||
android:layout_alignParentRight="true"
|
||||
style="?android:attr/buttonStyleSmall"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -7,4 +7,8 @@
|
|||
|
||||
<string name="dialog_move_certs_message">Should they be moved to system storage?</string>
|
||||
|
||||
<string name="move_to_system">Move to System</string>
|
||||
|
||||
<string name="delete">Delete</string>
|
||||
|
||||
</resources>
|
||||
|
|
Reference in a new issue