Switch filters
This commit is contained in:
parent
e1ae2e9c9d
commit
d7a0b37e5e
|
@ -17,7 +17,6 @@ package app.fedilab.android.asynctasks;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -201,6 +200,8 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
this.name = retrieveFeedsParam.getName();
|
this.name = retrieveFeedsParam.getName();
|
||||||
this.currentfilter = retrieveFeedsParam.getCurrentfilter();
|
this.currentfilter = retrieveFeedsParam.getCurrentfilter();
|
||||||
this.social = retrieveFeedsParam.getSocial();
|
this.social = retrieveFeedsParam.getSocial();
|
||||||
|
this.instanceName = retrieveFeedsParam.getInstanceName();
|
||||||
|
this.remoteInstance = retrieveFeedsParam.getRemoteInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,19 +231,21 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
apiResponse = api.getConversationTimeline(max_id);
|
apiResponse = api.getConversationTimeline(max_id);
|
||||||
break;
|
break;
|
||||||
case REMOTE_INSTANCE_FILTERED:
|
case REMOTE_INSTANCE_FILTERED:
|
||||||
if( this.social.equals("MASTODON")) {
|
if( this.social != null && this.social.equals("MASTODON")) {
|
||||||
apiResponse = api.getPublicTimelineTag(this.currentfilter, true, max_id,this.instanceName);
|
apiResponse = api.getPublicTimelineTag(this.currentfilter, true, max_id,this.remoteInstance);
|
||||||
List<app.fedilab.android.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
|
if( apiResponse != null){
|
||||||
if( statusesTemp != null){
|
List<app.fedilab.android.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
|
||||||
for(app.fedilab.android.client.Entities.Status status: statusesTemp){
|
if( statusesTemp != null){
|
||||||
status.setType(action);
|
for(app.fedilab.android.client.Entities.Status status: statusesTemp){
|
||||||
|
status.setType(action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(this.social.equals("GNU") ) {
|
} else if(this.social != null && this.social.equals("GNU") ) {
|
||||||
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
GNUAPI gnuapi = new GNUAPI(this.contextReference.get());
|
||||||
apiResponse = gnuapi.searchRemote(instanceName,currentfilter,max_id);
|
apiResponse = gnuapi.searchRemote(this.remoteInstance,currentfilter,max_id);
|
||||||
}else {
|
}else {
|
||||||
apiResponse = api.searchPeertube(instanceName, currentfilter);
|
apiResponse = api.searchPeertube(this.remoteInstance, currentfilter);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REMOTE_INSTANCE:
|
case REMOTE_INSTANCE:
|
||||||
|
|
|
@ -1485,6 +1485,7 @@ public class API {
|
||||||
statuses = parseStatuses(context, new JSONArray(response));
|
statuses = parseStatuses(context, new JSONArray(response));
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
|
e.printStackTrace();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class ManageTimelines {
|
||||||
private RemoteInstance remoteInstance;
|
private RemoteInstance remoteInstance;
|
||||||
private TagTimeline tagTimeline;
|
private TagTimeline tagTimeline;
|
||||||
private List listTimeline;
|
private List listTimeline;
|
||||||
|
private String currentFilter;
|
||||||
|
|
||||||
|
|
||||||
private boolean notif_follow, notif_add, notif_mention, notif_share, notif_poll;
|
private boolean notif_follow, notif_add, notif_mention, notif_share, notif_poll;
|
||||||
|
@ -972,14 +973,67 @@ public class ManageTimelines {
|
||||||
remoteInstance = tl.getRemoteInstance();
|
remoteInstance = tl.getRemoteInstance();
|
||||||
if( remoteInstance == null)
|
if( remoteInstance == null)
|
||||||
return;
|
return;
|
||||||
String currentFilter = remoteInstance.getFilteredWith();
|
currentFilter = remoteInstance.getFilteredWith();
|
||||||
popup.getMenuInflater()
|
|
||||||
.inflate(R.menu.option_instance_timeline, popup.getMenu());
|
final boolean[] changes = {false};
|
||||||
|
|
||||||
|
String title;
|
||||||
|
if( currentFilter == null) {
|
||||||
|
title = "✔ " + context.getString(R.string.all);
|
||||||
|
}else{
|
||||||
|
title = context.getString(R.string.all);
|
||||||
|
}
|
||||||
|
|
||||||
|
MenuItem itemall = popup.getMenu().add(0, 0, Menu.NONE, title);
|
||||||
|
|
||||||
|
itemall.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||||
|
item.setActionView(new View(context));
|
||||||
|
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
changes[0] = true;
|
||||||
|
FragmentTransaction fragTransaction = ((MainActivity)context).getSupportFragmentManager().beginTransaction();
|
||||||
|
DisplayStatusFragment displayStatusFragment = (DisplayStatusFragment) mPageReferenceMap.get(tl.getPosition());
|
||||||
|
if( displayStatusFragment == null)
|
||||||
|
return false;
|
||||||
|
tl.getRemoteInstance().setFilteredWith(null);
|
||||||
|
remoteInstance.setFilteredWith(null);
|
||||||
|
currentFilter = null;
|
||||||
|
new InstancesDAO(context, db).updateInstance(remoteInstance);
|
||||||
|
tl.setRemoteInstance(remoteInstance);
|
||||||
|
new TimelinesDAO(context, db).updateRemoteInstance(tl);
|
||||||
|
fragTransaction.detach(displayStatusFragment);
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("remote_instance", tl.getRemoteInstance().getHost()!=null?tl.getRemoteInstance().getHost():"");
|
||||||
|
bundle.putString("instanceType", tl.getRemoteInstance().getType());
|
||||||
|
bundle.putInt("timelineId", tl.getId());
|
||||||
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
|
||||||
|
displayStatusFragment.setArguments(bundle);
|
||||||
|
fragTransaction.attach(displayStatusFragment);
|
||||||
|
fragTransaction.commit();
|
||||||
|
popup.getMenu().close();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
java.util.List<String> tags = remoteInstance.getTags();
|
java.util.List<String> tags = remoteInstance.getTags();
|
||||||
if( tags != null && tags.size() > 0){
|
if( tags != null && tags.size() > 0){
|
||||||
java.util.Collections.sort(tags);
|
java.util.Collections.sort(tags);
|
||||||
for(String tag: tags){
|
for(String tag: tags){
|
||||||
String title = "";
|
if( tag == null || tag.length() == 0 )
|
||||||
|
continue;
|
||||||
if( currentFilter != null && currentFilter.equals(tag)) {
|
if( currentFilter != null && currentFilter.equals(tag)) {
|
||||||
title = "✔ " + tag;
|
title = "✔ " + tag;
|
||||||
}else{
|
}else{
|
||||||
|
@ -994,21 +1048,18 @@ public class ManageTimelines {
|
||||||
if( displayStatusFragment == null)
|
if( displayStatusFragment == null)
|
||||||
return false;
|
return false;
|
||||||
tl.getRemoteInstance().setFilteredWith(tag);
|
tl.getRemoteInstance().setFilteredWith(tag);
|
||||||
|
remoteInstance.setFilteredWith(tag);
|
||||||
new InstancesDAO(context, db).updateInstance(remoteInstance);
|
new InstancesDAO(context, db).updateInstance(remoteInstance);
|
||||||
tl.setRemoteInstance(remoteInstance);
|
tl.setRemoteInstance(remoteInstance);
|
||||||
new TimelinesDAO(context, db).updateRemoteInstance(tl);
|
new TimelinesDAO(context, db).updateRemoteInstance(tl);
|
||||||
|
currentFilter = tl.getRemoteInstance().getFilteredWith();
|
||||||
fragTransaction.detach(displayStatusFragment);
|
fragTransaction.detach(displayStatusFragment);
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("remote_instance", tl.getRemoteInstance().getHost()!=null?tl.getRemoteInstance().getHost():"");
|
bundle.putString("remote_instance", tl.getRemoteInstance().getHost()!=null?tl.getRemoteInstance().getHost():"");
|
||||||
bundle.putString("instanceType", tl.getRemoteInstance().getType());
|
bundle.putString("instanceType", tl.getRemoteInstance().getType());
|
||||||
bundle.putInt("timelineId", tl.getId());
|
bundle.putInt("timelineId", tl.getId());
|
||||||
if( currentFilter == null){
|
bundle.putString("currentfilter", tl.getRemoteInstance().getFilteredWith());
|
||||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE_FILTERED);
|
||||||
}else{
|
|
||||||
bundle.putString("currentfilter", tl.getRemoteInstance().getFilteredWith());
|
|
||||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE_FILTERED);
|
|
||||||
}
|
|
||||||
displayStatusFragment.setArguments(bundle);
|
displayStatusFragment.setArguments(bundle);
|
||||||
fragTransaction.attach(displayStatusFragment);
|
fragTransaction.attach(displayStatusFragment);
|
||||||
fragTransaction.commit();
|
fragTransaction.commit();
|
||||||
|
@ -1018,7 +1069,58 @@ public class ManageTimelines {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean[] changes = {false};
|
|
||||||
|
MenuItem itemadd = popup.getMenu().add(0, 0, Menu.NONE, context.getString(R.string.add_tags));
|
||||||
|
itemadd.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||||
|
item.setActionView(new View(context));
|
||||||
|
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
changes[0] = true;
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
|
||||||
|
LayoutInflater inflater = ((MainActivity)context).getLayoutInflater();
|
||||||
|
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.tags_instance, null);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
final EditText editText = dialogView.findViewById(R.id.filter_words);
|
||||||
|
if(remoteInstance.getTags() != null) {
|
||||||
|
String valuesTag = "";
|
||||||
|
for(String val: remoteInstance.getTags())
|
||||||
|
valuesTag += val+" ";
|
||||||
|
editText.setText(valuesTag);
|
||||||
|
editText.setSelection(editText.getText().toString().length());
|
||||||
|
}
|
||||||
|
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
String[] values = editText.getText().toString().trim().split("\\s+");
|
||||||
|
java.util.List<String> tags =
|
||||||
|
new ArrayList<>(Arrays.asList(values));
|
||||||
|
remoteInstance.setTags(tags);
|
||||||
|
new InstancesDAO(context, db).updateInstance(remoteInstance);
|
||||||
|
tl.setRemoteInstance(remoteInstance);
|
||||||
|
new TimelinesDAO(context, db).updateRemoteInstance(tl);
|
||||||
|
popup.getMenu().clear();
|
||||||
|
popup.getMenu().close();
|
||||||
|
instanceClick(context, tl, tabStrip, position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(PopupMenu menu) {
|
public void onDismiss(PopupMenu menu) {
|
||||||
|
@ -1045,56 +1147,6 @@ public class ManageTimelines {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
|
||||||
item.setActionView(new View(context));
|
|
||||||
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
changes[0] = true;
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.action_add_tags:
|
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
|
|
||||||
LayoutInflater inflater = ((MainActivity)context).getLayoutInflater();
|
|
||||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.tags_instance, null);
|
|
||||||
dialogBuilder.setView(dialogView);
|
|
||||||
final EditText editText = dialogView.findViewById(R.id.filter_words);
|
|
||||||
if(remoteInstance.getTags() != null) {
|
|
||||||
String valuesTag = "";
|
|
||||||
for(String val: remoteInstance.getTags())
|
|
||||||
valuesTag += val+" ";
|
|
||||||
editText.setText(valuesTag);
|
|
||||||
editText.setSelection(editText.getText().toString().length());
|
|
||||||
}
|
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
String[] values = editText.getText().toString().trim().split("\\s+");
|
|
||||||
java.util.List<String> tags =
|
|
||||||
new ArrayList<>(Arrays.asList(values));
|
|
||||||
remoteInstance.setTags(tags);
|
|
||||||
new InstancesDAO(context, db).updateInstance(remoteInstance);
|
|
||||||
tl.setRemoteInstance(remoteInstance);
|
|
||||||
new TimelinesDAO(context, db).updateRemoteInstance(tl);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AlertDialog alertDialog = dialogBuilder.create();
|
|
||||||
alertDialog.show();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
popup.show();
|
popup.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_add_tags"
|
|
||||||
app:showAsAction="always"
|
|
||||||
android:title="@string/add_tags" />
|
|
||||||
</menu>
|
|
|
@ -947,7 +947,7 @@
|
||||||
<string name="set_blur_sensitive">Blur sensitive media</string>
|
<string name="set_blur_sensitive">Blur sensitive media</string>
|
||||||
<string name="set_display_timeline_in_list">Display timelines in a list</string>
|
<string name="set_display_timeline_in_list">Display timelines in a list</string>
|
||||||
<string name="display_timeline">Display timelines</string>
|
<string name="display_timeline">Display timelines</string>
|
||||||
<string name="add_tags">Add tags</string>
|
<string name="add_tags">Manage tags</string>
|
||||||
|
|
||||||
<plurals name="number_of_vote">
|
<plurals name="number_of_vote">
|
||||||
<item quantity="one">%d vote</item>
|
<item quantity="one">%d vote</item>
|
||||||
|
|
Loading…
Reference in New Issue