Skip to content

Issue #694 - unstarring on gallery view is now possible #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.seafile.seadroid2.ui.activity;

import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -8,7 +9,9 @@
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.common.collect.Lists;
import com.seafile.seadroid2.data.SeafStarredFile;
import com.seafile.seadroid2.ui.HackyViewPager;
import com.seafile.seadroid2.util.ConcurrentAsyncTask;
import com.seafile.seadroid2.R;
Expand Down Expand Up @@ -53,10 +56,13 @@ public class GalleryActivity extends BaseActivity {
private String fileName;
private String STATE_FILE_NAME;
private int mPageIndex;
private boolean starred;
private GalleryAdapter mGalleryAdapter;
private List<SeafPhoto> mPhotos = Lists.newArrayList();

/** flag to mark if the tool bar was shown */
/**
* flag to mark if the tool bar was shown
*/
private boolean showToolBar = true;
private View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
Expand All @@ -66,7 +72,11 @@ public void onClick(View v) {
deleteFile(repoID, Utils.pathJoin(dirPath, fileName));
break;
case R.id.gallery_star_photo:
starFile(repoID, dirPath, fileName);
Log.e("Starred", "" + starred);
if (!starred)
starFile(repoID, dirPath, fileName);
else
unStarFile(repoID, dirPath, fileName);
break;
case R.id.gallery_share_photo:
shareFile(repoID, false, Utils.pathJoin(dirPath, fileName));
Expand All @@ -87,6 +97,7 @@ public void onCreate(Bundle savedInstanceState) {
mToolbar = (LinearLayout) findViewById(R.id.gallery_tool_bar);
mDeleteBtn.setOnClickListener(onClickListener);
mStarBtn.setOnClickListener(onClickListener);
mStarBtn.setImageResource(R.drawable.star_normal);
mShareBtn.setOnClickListener(onClickListener);
mViewPager = (HackyViewPager) findViewById(R.id.gallery_pager);
mViewPager.setPageTransformer(true, new ZoomOutPageTransformer());
Expand All @@ -105,10 +116,12 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
}

@Override
public void onPageSelected(int position) {}
public void onPageSelected(int position) {
}

@Override
public void onPageScrollStateChanged(int state) {}
public void onPageScrollStateChanged(int state) {
}
});

mPageIndexContainer = (LinearLayout) findViewById(R.id.page_index_container);
Expand All @@ -123,6 +136,17 @@ public void onPageScrollStateChanged(int state) {}
fileName = getIntent().getStringExtra("fileName");
dataMgr = new DataManager(mAccount);

for (SeafStarredFile seafStarredFile : dataMgr.getCachedStarredFiles()) {
Log.e("RepoID", "Chached: " + seafStarredFile.getRepoID() + " | File: " + repoID);
Log.e("Path", "Chached: " + seafStarredFile.getPath() + " | File: " + (dirPath + "/" + fileName));
if (seafStarredFile.getRepoID().equals(repoID) && seafStarredFile.getPath().equals(dirPath + "/" + fileName)) {
Log.e("Found", "found");
starred = true;
mStarBtn.setImageResource(R.drawable.star_selected);
break;
}
}

displayPhotosInGallery(repoName, repoID, dirPath);
}

Expand Down Expand Up @@ -152,11 +176,12 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) {
* Load thumbnail urls in order to display them in the gallery.
* Prior to use caches to calculate those urls.
* If caches are not available, load them asynchronously.
*
* <p>
* NOTE: When user browsing files in "LIBRARY" tab, he has to navigate into a repo in order to open gallery.
* Method which get called is {@link com.seafile.seadroid2.ui.fragment.ReposFragment#navToReposView(boolean)} or {@link com.seafile.seadroid2.ui.fragment.ReposFragment#navToDirectory(boolean)},
* so seafDirents were already cached and it will always use them to calculate thumbnail urls for displaying photos in gallery.
* But for browsing "STARRED" tab, caches of starred files may or may not cached, that is where the asynchronous loading code segment comes into use.
*
* @param repoID
* @param dirPath
*/
Expand Down Expand Up @@ -276,7 +301,7 @@ public List<SeafDirent> sortFiles(List<SeafDirent> dirents, int type, int order)
}
} else if (type == SeafItemAdapter.SORT_BY_LAST_MODIFIED_TIME) {
// sort by last modified time, in ascending order
Collections.sort(dirents, new SeafDirent.DirentLastMTimeComparator());
Collections.sort(dirents, new SeafDirent.DirentLastMTimeComparator());
if (order == SeafItemAdapter.SORT_ORDER_DESCENDING) {
Collections.reverse(dirents);
}
Expand All @@ -287,7 +312,6 @@ public List<SeafDirent> sortFiles(List<SeafDirent> dirents, int type, int order)
/**
* Dynamically navigate to the starting page index selected by user
* by default the starting page index is 0
*
*/
private void navToSelectedPage() {
int size = mPhotos.size();
Expand Down Expand Up @@ -345,6 +369,16 @@ private void starFile(String repoId, String dir, String fileName) {
ConcurrentAsyncTask.execute(new StarFileTask(repoId, p));
}

private void unStarFile(String repoId, String dir, String fileName) {
if (!Utils.isNetworkOn()) {
showShortToast(this, R.string.network_down);
return;
}

String p = Utils.pathJoin(dir, fileName);
ConcurrentAsyncTask.execute(new UnStarFileTask(repoId, p));
}

private void shareFile(String repoID, boolean isEncrypt, String path) {
if (isEncrypt) {
WidgetUtils.inputSharePassword(this, repoID, path, false, mAccount);
Expand Down Expand Up @@ -386,6 +420,46 @@ protected void onPostExecute(Void v) {
}

showShortToast(GalleryActivity.this, R.string.star_file_succeed);
starred = true;
mStarBtn.setImageResource(R.drawable.star_selected);
}
}

class UnStarFileTask extends AsyncTask<Void, Void, Void> {
private String repoId;
private String path;
private SeafException err;

public UnStarFileTask(String repoId, String path) {
this.repoId = repoId;
this.path = path;
}

@Override
protected Void doInBackground(Void... params) {

if (dataMgr == null)
return null;

try {
dataMgr.unstar(repoId, path);
} catch (SeafException e) {
err = e;
}

return null;
}

@Override
protected void onPostExecute(Void v) {
if (err != null) {
showShortToast(GalleryActivity.this, R.string.unstar_file_failed);
return;
}

showShortToast(GalleryActivity.this, R.string.unstar_file_succeed);
starred = false;
mStarBtn.setImageResource(R.drawable.star_normal);
}
}

Expand All @@ -406,7 +480,7 @@ private void removePageAndRefreshView() {
return;
}

mPageIndex = mPageIndex > size - 1 ? size -1 : mPageIndex;
mPageIndex = mPageIndex > size - 1 ? size - 1 : mPageIndex;
// page index starting from 1 instead of 0 in user interface, so plus one here
mPageIndexTextView.setText(String.valueOf(mPageIndex + 1));

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ Zum Aktualisieren einmal antippen</string>
<string name="star_file_succeed">Als Favorit markiert</string>
<string name="star_file_failed">Markieren als Favorit nicht möglich</string>
<!--unstar a file-->
<string name="unstar_file_succeed">Markierung entfernt</string>
<string name="unstar_file_failed">Entfernen der Markierung fehlgeschlagen</string>
<string name="unstar">Markierung entfernen</string>
<!--notification bar-->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@
<string name="star_file_failed">File starred failed</string>

<!-- unstar a file -->
<string name="unstar_file_succeed">Unstarring the file successfully</string>
<string name="unstar_file_failed">Unstarring the file failed</string>
<string name="unstar">Unstar</string>

Expand Down