Skip to content

Commit

Permalink
added clear button to history and favourite activity
Browse files Browse the repository at this point in the history
  • Loading branch information
PureDark committed Aug 31, 2016
1 parent f0b933a commit 17afea9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
Expand Down Expand Up @@ -123,15 +124,15 @@ private void initCover(String cover) {
private void parseCollection(LocalCollection collection) {
if(collection==null)
return;
if (collection.cover != null && !collection.cover.startsWith("file://"))
collection.cover = "file://" + collection.cover;
if (collection.pictures != null) {
for (Picture picture : collection.pictures) {
if (picture.thumbnail != null && !picture.thumbnail.startsWith("file://"))
picture.thumbnail = "file://" + picture.thumbnail;
if (picture.pic != null && !picture.pic.startsWith("file://"))
picture.pic = "file://" + picture.pic;
}
if(collection.pictures.size()>0)
collection.cover = collection.pictures.get(0).pic;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ void back() {
onBackPressed();
}

@OnClick(R.id.btn_clear_all)
void clear() {
new AlertDialog.Builder(FavouriteActivity.this).setTitle("是否清空收藏夹?")
.setMessage("清空后将无法恢复")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
favouriteHolder.clear();
adapter.getDataProvider().setDataSet(favouriteHolder.getFavourites());
adapter.notifyDataSetChanged();
}
}).setNegativeButton("取消", null).show();
}

@Override
public void onDestroy(){
if(favouriteHolder!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ void back() {
onBackPressed();
}

@OnClick(R.id.btn_clear_all)
void clear() {
new AlertDialog.Builder(HistoryActivity.this).setTitle("是否清空历史纪录?")
.setMessage("清空后将无法恢复")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
historyHolder.clear();
adapter.getDataProvider().setDataSet(historyHolder.getHistories());
adapter.notifyDataSetChanged();
}
}).setNegativeButton("取消", null).show();
}

@Override
public void onDestroy(){
if(historyHolder!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ public void onCreate(final Bundle savedInstanceState) {
if (downloadPath != null)
getPreferenceManager().findPreference(KEY_PREF_DOWNLOAD_PATH).setSummary(downloadPath);
getPreferenceScreen().setOnPreferenceChangeListener(this);
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
.initialDirectory(downloadPath)
.newDirectoryName("download")
.allowNewDirectoryNameModification(true)
.build();
mDialog = DirectoryChooserFragment.newInstance(config);
mDialog.setTargetFragment(this, 0);
}

@Override
Expand Down Expand Up @@ -144,6 +137,14 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
Intent intent = new Intent(activity, AboutActivity.class);
startActivity(intent);
} else if (preference.getKey().equals(KEY_PREF_DOWNLOAD_PATH)) {
String downloadPath = DownloadManager.getDownloadPath();
final DirectoryChooserConfig config = DirectoryChooserConfig.builder()
.initialDirectory(downloadPath)
.newDirectoryName("download")
.allowNewDirectoryNameModification(true)
.build();
mDialog = DirectoryChooserFragment.newInstance(config);
mDialog.setTargetFragment(this, 0);
mDialog.show(getFragmentManager(), null);
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void addFavourite(LocalCollection item) {
dbHelper.insert(dbName, contentValues);
}

public void clear(){
dbHelper.delete(dbName, "", null);
}

public void deleteFavourite(Collection item) {
dbHelper.delete(dbName, "`idCode` = ? AND `title` = ? AND `referer` = ?",
new String[]{item.idCode, item.title, item.referer});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public void addHistory(LocalCollection item) {
dbHelper.insert(dbName, contentValues);
}

public void clear(){
dbHelper.delete(dbName, "", null);
}

public void deleteHistory(Collection item) {
dbHelper.delete(dbName, "`idCode` = ? AND `title` = ? AND `referer` = ?",
new String[]{item.idCode, item.title, item.referer});
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/ic_clear_all_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#FFF" android:pathData="M5,13H19V11H5M3,17H17V15H3M7,7V9H21V7" />
</vector>
18 changes: 14 additions & 4 deletions app/src/main/res/layout/activity_collection_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="-16dp"
android:paddingStart="-16dp"
android:paddingEnd="16dp"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay">

<LinearLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false">
Expand All @@ -39,11 +40,20 @@

<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="@dimen/tool_bar_height"
android:layout_weight="1"
android:gravity="center"
android:text=""
android:textAppearance="@style/ActionBar.Title" />

<ImageView
android:id="@+id/btn_clear_all"
android:layout_width="@dimen/tool_bar_height"
android:layout_height="@dimen/tool_bar_height"
android:padding="14dp"
android:background="@drawable/bg_button"
app:srcCompat="@drawable/ic_clear_all_white"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Expand Down

0 comments on commit 17afea9

Please sign in to comment.