Allow to add followed instance in the reorder tabs activity

This commit is contained in:
tom79 2019-05-04 18:28:47 +02:00
parent f8e395cae8
commit 1adfa71875
10 changed files with 319 additions and 634 deletions

View File

@ -49,48 +49,28 @@ import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveInstanceAsyncTask;
@ -104,12 +84,10 @@ import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Filters;
import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
import fr.gouv.etalab.mastodon.client.Entities.Version;
import fr.gouv.etalab.mastodon.client.HttpsConnection;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayBookmarksFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayDraftsFragment;
@ -131,7 +109,6 @@ import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.helper.MenuFloating;
import fr.gouv.etalab.mastodon.interfaces.OnFilterActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiAccountInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface;
@ -141,7 +118,6 @@ import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
import fr.gouv.etalab.mastodon.services.BackupStatusService;
import fr.gouv.etalab.mastodon.services.LiveNotificationService;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO;
@ -175,7 +151,7 @@ import static fr.gouv.etalab.mastodon.sqlite.Sqlite.importDB;
public abstract class BaseMainActivity extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface, OnRetrieveRemoteAccountInterface, OnRetrieveEmojiAccountInterface, OnFilterActionInterface, OnListActionInterface, OnSyncTimelineInterface {
implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface, OnRetrieveRemoteAccountInterface, OnRetrieveEmojiAccountInterface, OnFilterActionInterface, OnSyncTimelineInterface {
private FloatingActionButton toot, delete_all, add_new;
private HashMap<String, String> tagTile = new HashMap<>();
@ -188,25 +164,18 @@ public abstract class BaseMainActivity extends BaseActivity
private ViewPager viewPager;
private RelativeLayout main_app_container;
public static List<Filters> filters = new ArrayList<>();
public static int countNewStatus;
public static int countNewNotifications;
public static String lastHomeId = null, lastNotificationId = null;
private AppBarLayout appBar;
private String userId;
private String instance;
public int countPage;
private PagerAdapter adapter;
private String oldSearch;
boolean isLoadingInstance = false;
private ImageView delete_instance;
public static String displayPeertube = null;
private PopupMenu popup;
private String instance_id;
private int style;
private Activity activity;
public static HashMap<Integer, RetrieveFeedsAsyncTask.Type> typePosition = new HashMap<>();
private FloatingActionButton federatedTimelines;
public static UpdateAccountInfoAsyncTask.SOCIAL social;
private final int PICK_IMPORT = 5556;
private AlertDialog.Builder dialogBuilderOptin;
@ -424,10 +393,6 @@ public abstract class BaseMainActivity extends BaseActivity
delete_instance.setVisibility(View.GONE);
Helper.switchLayout(BaseMainActivity.this);
tootShow();
if( !displayFollowInstance)
federatedTimelines.hide();
else
federatedTimelinesShow();
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
if( tab.getCustomView() != null) {
@ -558,10 +523,6 @@ public abstract class BaseMainActivity extends BaseActivity
delete_instance.setVisibility(View.GONE);
Helper.switchLayout(BaseMainActivity.this);
tootShow();
if( !displayFollowInstance)
federatedTimelines.hide();
else
federatedTimelinesShow();
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
if( tab.getCustomView() != null) {
@ -618,7 +579,6 @@ public abstract class BaseMainActivity extends BaseActivity
style = R.style.Dialog;
}
displayFollowInstances();
if( theme == THEME_LIGHT){
changeDrawableColor(getApplicationContext(), R.drawable.ic_home,R.color.dark_icon);
@ -1705,38 +1665,6 @@ public abstract class BaseMainActivity extends BaseActivity
}
}
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
if( apiResponse.getError() != null){
return;
}
if( actionType == ManageListsAsyncTask.action.GET_LIST && popup != null) {
if (apiResponse.getLists() != null && apiResponse.getLists().size() > 0) {
SubMenu submList = popup.getMenu().findItem(R.id.action_show_list).getSubMenu();
int l = 0;
for (fr.gouv.etalab.mastodon.client.Entities.List list : apiResponse.getLists()) {
MenuItem itemPlaceHolder = submList.findItem(R.id.list_instances);
if( itemPlaceHolder != null)
itemPlaceHolder.setVisible(false);
MenuItem item = submList.add(0, l, Menu.NONE, list.getTitle());
item.setIcon(R.drawable.ic_list_instance);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(BaseMainActivity.this, ListActivity.class);
Bundle b = new Bundle();
b.putString("id", list.getId());
b.putString("title", list.getTitle());
intent.putExtras(b);
startActivity(intent);
return false;
}
});
l++;
}
}
}
}
@ -1758,7 +1686,7 @@ public abstract class BaseMainActivity extends BaseActivity
position = (timelines.size()-1);
if( position < 0)
position = 0;
setTitle("");
/*if( !optimize_loading)
viewPager.setOffscreenPageLimit(countPage);*/
viewPager.setOffscreenPageLimit(2);
@ -1777,13 +1705,8 @@ public abstract class BaseMainActivity extends BaseActivity
Helper.switchLayout(BaseMainActivity.this);
if( manageTimelines.size() > tab.getPosition() && (manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.NOTIFICATION ||manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.ART || manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.PEERTUBE)) {
toot.hide();
federatedTimelines.hide();
}else {
tootShow();
if( !displayFollowInstance)
federatedTimelines.hide();
else
federatedTimelinesShow();
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
@ -1822,13 +1745,8 @@ public abstract class BaseMainActivity extends BaseActivity
}
if( manageTimelines.size() > tab.getPosition() && (manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.ART || manageTimelines.get(tab.getPosition()).getType() == ManageTimelines.Type.PEERTUBE)) {
toot.hide();
federatedTimelines.hide();
}else {
tootShow();
if( !displayFollowInstance)
federatedTimelines.hide();
else
federatedTimelinesShow();
}
if( viewPager.getAdapter() != null) {
@ -2137,17 +2055,11 @@ public abstract class BaseMainActivity extends BaseActivity
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE ||social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA|| social == UpdateAccountInfoAsyncTask.SOCIAL.GNU|| social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
if (display) {
tootShow();
if (!displayFollowInstance)
federatedTimelines.hide();
else
federatedTimelinesShow();
} else {
toot.hide();
federatedTimelines.hide();
}
}else {
toot.hide();
federatedTimelines.hide();
}
}
public void tootShow(){
@ -2157,13 +2069,7 @@ public abstract class BaseMainActivity extends BaseActivity
toot.hide();
}
}
public void federatedTimelinesShow(){
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
federatedTimelines.show();
}else{
federatedTimelines.hide();
}
}
@ -2171,438 +2077,5 @@ public abstract class BaseMainActivity extends BaseActivity
return toot.getVisibility() == View.VISIBLE;
}
public void refreshButton(){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
FloatingActionButton federatedTimelines = findViewById(R.id.federated_timeline);
boolean displayFollowInstance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
if( !displayFollowInstance)
federatedTimelines.hide();
else
federatedTimelinesShow();
}
private void displayFollowInstances(){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(BaseMainActivity.this, DB_NAME, null, Sqlite.DB_VERSION).open();
federatedTimelines = findViewById(R.id.federated_timeline);
federatedTimelinesShow();
delete_instance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
String title = toolbarTitle.getText().toString();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style);
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
new InstancesDAO(BaseMainActivity.this, db).remove(instance_id);
BaseMainActivity.this.onBackPressed();
}
});
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
dialogBuilder.setTitle(R.string.delete_instance);
dialogBuilder.setMessage(getString(R.string.warning_delete_instance, title));
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}catch (Exception e){
Toasty.error(BaseMainActivity.this, getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
}
}
});
boolean displayFollowInstance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
if( !displayFollowInstance)
federatedTimelines.hide();
federatedTimelines.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA)
new ManageListsAsyncTask(BaseMainActivity.this, ManageListsAsyncTask.action.GET_LIST, null, null, null, null, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
SQLiteDatabase db = Sqlite.getInstance(BaseMainActivity.this, DB_NAME, null, Sqlite.DB_VERSION).open();
new InstancesDAO(BaseMainActivity.this, db).cleanDoublon();
List<RemoteInstance> remoteInstances = new InstancesDAO(BaseMainActivity.this, db).getAllInstances();
popup = new PopupMenu(BaseMainActivity.this, federatedTimelines);
popup.getMenuInflater()
.inflate(R.menu.remote_instances, popup.getMenu());
try {
@SuppressLint("PrivateApi") Method method = popup.getMenu().getClass().getDeclaredMethod("setOptionalIconsVisible", boolean.class);
method.setAccessible(true);
method.invoke(popup.getMenu(), true);
} catch (Exception e) {
e.printStackTrace();
}
if(remoteInstances != null) {
SubMenu submMastodon = popup.getMenu().findItem(R.id.action_show_mastodon).getSubMenu();
SubMenu submPeertube = popup.getMenu().findItem(R.id.action_show_peertube).getSubMenu();
SubMenu submPixelfed = popup.getMenu().findItem(R.id.action_show_pixelfed).getSubMenu();
SubMenu submMisskey = popup.getMenu().findItem(R.id.action_show_misskey).getSubMenu();
SubMenu submChannel = popup.getMenu().findItem(R.id.action_show_channel).getSubMenu();
int i = 0, j = 0 , k = 0, l = 0 , m = 0;
for (RemoteInstance remoteInstance : remoteInstances) {
if (remoteInstance.getType() == null || remoteInstance.getType().equals("MASTODON")) {
MenuItem itemPlaceHolder = submMastodon.findItem(R.id.mastodon_instances);
if( itemPlaceHolder != null)
itemPlaceHolder.setVisible(false);
MenuItem item = submMastodon.add(0, i, Menu.NONE, remoteInstance.getHost());
item.setIcon(R.drawable.mastodon_icon_item);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", remoteInstance.getHost());
statusFragment.setArguments(bundle);
String fragmentTag = "REMOTE_INSTANCE";
instance_id = remoteInstance.getDbID();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
delete_instance.setVisibility(View.VISIBLE);
toolbarTitle.setText(remoteInstance.getHost());
return false;
}
});
i++;
}
if (remoteInstance.getType() == null || remoteInstance.getType().equals("PEERTUBE_CHANNEL")) {
MenuItem itemPlaceHolder = submChannel.findItem(R.id.channel_instances);
if( itemPlaceHolder != null)
itemPlaceHolder.setVisible(false);
MenuItem item = submChannel.add(0, k, Menu.NONE, remoteInstance.getId() + " - " +remoteInstance.getHost());
item.setIcon(R.drawable.ic_list_instance);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", remoteInstance.getHost());
bundle.putString("remote_channel_name", remoteInstance.getId());
bundle.putString("instanceType", "PEERTUBE");
statusFragment.setArguments(bundle);
instance_id = remoteInstance.getDbID();
String fragmentTag = "REMOTE_INSTANCE";
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
delete_instance.setVisibility(View.VISIBLE);
toolbarTitle.setText(remoteInstance.getHost());
return false;
}
});
k++;
}
if (remoteInstance.getType() == null || remoteInstance.getType().equals("PIXELFED")) {
MenuItem itemPlaceHolder = submPixelfed.findItem(R.id.pixelfed_instance);
if( itemPlaceHolder != null)
itemPlaceHolder.setVisible(false);
MenuItem item = submPixelfed.add(0, j, Menu.NONE, remoteInstance.getHost());
item.setIcon(R.drawable.pixelfed);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", remoteInstance.getHost());
bundle.putString("instanceType", "PIXELFED");
statusFragment.setArguments(bundle);
String fragmentTag = "REMOTE_INSTANCE";
instance_id = remoteInstance.getDbID();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
delete_instance.setVisibility(View.VISIBLE);
toolbarTitle.setText(remoteInstance.getHost());
return false;
}
});
j++;
}
if (remoteInstance.getType() == null || remoteInstance.getType().equals("MISSKEY")) {
MenuItem itemPlaceHolder = submMisskey.findItem(R.id.misskey_instance);
if( itemPlaceHolder != null)
itemPlaceHolder.setVisible(false);
MenuItem item = submMisskey.add(0, l, Menu.NONE, remoteInstance.getHost());
item.setIcon(R.drawable.misskey);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", remoteInstance.getHost());
statusFragment.setArguments(bundle);
bundle.putString("instanceType", "MISSKEY");
String fragmentTag = "REMOTE_INSTANCE";
instance_id = remoteInstance.getDbID();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
delete_instance.setVisibility(View.VISIBLE);
toolbarTitle.setText(remoteInstance.getHost());
return false;
}
});
l++;
}
if (remoteInstance.getType() == null || remoteInstance.getType().equals("PEERTUBE")) {
MenuItem itemPlaceHolder = submPeertube.findItem(R.id.peertube_instances);
if( itemPlaceHolder != null)
itemPlaceHolder.setVisible(false);
MenuItem item = submPeertube.add(0, m, Menu.NONE, remoteInstance.getHost());
item.setIcon(R.drawable.peertube_icon);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", remoteInstance.getHost());
statusFragment.setArguments(bundle);
String fragmentTag = "REMOTE_INSTANCE";
bundle.putString("instanceType", "PEERTUBE");
instance_id = remoteInstance.getDbID();
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
delete_instance.setVisibility(View.VISIBLE);
toolbarTitle.setText(remoteInstance.getHost());
return false;
}
});
m++;
}
}
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_instance:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style);
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.search_instance, null);
dialogBuilder.setView(dialogView);
AutoCompleteTextView instance_list = dialogView.findViewById(R.id.search_instance);
//Manage download of attachments
RadioGroup radioGroup = dialogView.findViewById(R.id.set_attachment_group);
instance_list.setFilters(new InputFilter[]{new InputFilter.LengthFilter(60)});
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
String instanceName = instance_list.getText().toString().trim();
new Thread(new Runnable(){
@Override
public void run() {
try {
if(radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance)
new HttpsConnection(BaseMainActivity.this).get("https://" + instanceName + "/api/v1/timelines/public?local=true", 10, null, null);
else if( radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance)
new HttpsConnection(BaseMainActivity.this).get("https://" + instanceName + "/api/v1/videos/", 10, null, null);
else if( radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
new HttpsConnection(BaseMainActivity.this).get("https://" + instanceName + "/api/v1/timelines/public", 10, null, null);
}else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
new HttpsConnection(BaseMainActivity.this).post("https://" + instanceName + "/api/notes/local-timeline", 10, null, null);
}
runOnUiThread(new Runnable() {
public void run() {
JSONObject resobj;
dialog.dismiss();
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
statusFragment = new DisplayStatusFragment();
if(radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance) {
new InstancesDAO(BaseMainActivity.this, db).insertInstance(instanceName, "MASTODON");
bundle.putString("instanceType", "MASTODON");
}else if( radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance) {
new InstancesDAO(BaseMainActivity.this, db).insertInstance(instanceName, "PEERTUBE");
bundle.putString("instanceType", "PEERTUBE");
} else if( radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
new InstancesDAO(BaseMainActivity.this, db).insertInstance(instanceName, "PIXELFED");
bundle.putString("instanceType", "PIXELFED");
} else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
new InstancesDAO(BaseMainActivity.this, db).insertInstance(instanceName, "MISSKEY");
bundle.putString("instanceType", "MISSKEY");
}
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
bundle.putString("remote_instance", instanceName);
statusFragment.setArguments(bundle);
String fragmentTag = "REMOTE_INSTANCE";
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
delete_instance.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
toolbarTitle.setText(instanceName);
}
});
} catch (final Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
Toasty.warning(getApplicationContext(), getString(R.string.toast_instance_unavailable),Toast.LENGTH_LONG).show();
}
});
}
}
}).start();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(instance_list.getWindowToken(), 0);
}
});
if( alertDialog.getWindow() != null )
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
instance_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
oldSearch = parent.getItemAtPosition(position).toString().trim();
}
});
instance_list.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Pattern host = Pattern.compile("([\\da-z\\.-]+\\.[a-z\\.]{2,12})");
Matcher matcher = host.matcher(s.toString().trim());
if( s.toString().trim().length() == 0 || !matcher.find()) {
alertDialog.getButton(
AlertDialog.BUTTON_POSITIVE).setEnabled(false);
} else {
// Something into edit text. Enable the button.
alertDialog.getButton(
AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}
if (s.length() > 2 && !isLoadingInstance) {
final String action = "/instances/search";
final HashMap<String, String> parameters = new HashMap<>();
parameters.put("q", s.toString().trim());
parameters.put("count", String.valueOf(1000));
parameters.put("name", String.valueOf(true));
isLoadingInstance = true;
if( oldSearch == null || !oldSearch.equals(s.toString().trim()))
new Thread(new Runnable() {
@Override
public void run() {
try {
final String response = new HttpsConnection(BaseMainActivity.this).get("https://instances.social/api/1.0" + action, 30, parameters, Helper.THEKINRAR_SECRET_TOKEN);
runOnUiThread(new Runnable() {
public void run() {
isLoadingInstance = false;
String[] instances;
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("instances");
if (jsonArray != null) {
int length = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true"))
length++;
}
instances = new String[length];
int j = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true")) {
instances[j] = jsonArray.getJSONObject(i).get("name").toString();
j++;
}
}
} else {
instances = new String[]{};
}
instance_list.setAdapter(null);
ArrayAdapter<String> adapter =
new ArrayAdapter<>(BaseMainActivity.this, android.R.layout.simple_list_item_1, instances);
instance_list.setAdapter(adapter);
if (instance_list.hasFocus() && !BaseMainActivity.this.isFinishing())
instance_list.showDropDown();
oldSearch = s.toString().trim();
} catch (JSONException ignored) {
isLoadingInstance = false;
}
}
});
} catch (HttpsConnection.HttpsConnectionException e) {
isLoadingInstance = false;
} catch (Exception e) {
isLoadingInstance = false;
}
}
}).start();
else
isLoadingInstance = false;
}
}
});
break;
}
return true;
}
});
popup.show();
}
});
}
}

View File

@ -16,32 +16,64 @@ package fr.gouv.etalab.mastodon.activities;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import es.dmoral.toasty.Toasty;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines;
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
import fr.gouv.etalab.mastodon.client.HttpsConnection;
import fr.gouv.etalab.mastodon.drawers.ReorderTabAdapter;
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.OnStartDragListener;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.OnUndoListener;
import fr.gouv.etalab.mastodon.helper.itemtouchhelper.SimpleItemTouchHelperCallback;
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -50,6 +82,7 @@ import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.REFRESH_TIMELINE;
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
import static fr.gouv.etalab.mastodon.sqlite.Sqlite.DB_NAME;
/**
@ -57,7 +90,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
* Reorder timelines activity
*/
public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener, OnUndoListener {
public class ReorderTimelinesActivity extends BaseActivity implements OnStartDragListener, OnUndoListener, OnListActionInterface {
public static boolean updated;
private ItemTouchHelper touchHelper;
@ -66,6 +99,10 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
private List<ManageTimelines> timelines;
private ReorderTabAdapter adapter;
private boolean actionCanBeApplied;
private ManageTimelines timeline;
private boolean isLoadingInstance;
private String oldSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -84,6 +121,16 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
default:
setTheme(R.style.AppThemeDark);
}
isLoadingInstance = false;
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
style = R.style.DialogBlack;
}else {
style = R.style.Dialog;
}
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
@ -91,17 +138,201 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
if( actionBar != null ) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null);
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar_add, null);
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
ImageView add_remote_instance = actionBar.getCustomView().findViewById(R.id.add_remote_instance);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
add_remote_instance.setVisibility(View.VISIBLE);
}else{
add_remote_instance.setVisibility(View.GONE);
}
add_remote_instance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ReorderTimelinesActivity.this, style);
LayoutInflater inflater = getLayoutInflater();
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.search_instance, null);
dialogBuilder.setView(dialogView);
AutoCompleteTextView instance_list = dialogView.findViewById(R.id.search_instance);
//Manage download of attachments
RadioGroup radioGroup = dialogView.findViewById(R.id.set_attachment_group);
instance_list.setFilters(new InputFilter[]{new InputFilter.LengthFilter(60)});
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), DB_NAME, null, Sqlite.DB_VERSION).open();
String instanceName = instance_list.getText().toString().trim();
new Thread(new Runnable(){
@Override
public void run() {
try {
if(radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance)
new HttpsConnection(ReorderTimelinesActivity.this).get("https://" + instanceName + "/api/v1/timelines/public?local=true", 10, null, null);
else if( radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance)
new HttpsConnection(ReorderTimelinesActivity.this).get("https://" + instanceName + "/api/v1/videos/", 10, null, null);
else if( radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
new HttpsConnection(ReorderTimelinesActivity.this).get("https://" + instanceName + "/api/v1/timelines/public", 10, null, null);
}else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
new HttpsConnection(ReorderTimelinesActivity.this).post("https://" + instanceName + "/api/notes/local-timeline", 10, null, null);
}
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
if(radioGroup.getCheckedRadioButtonId() == R.id.mastodon_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "MASTODON");
}else if( radioGroup.getCheckedRadioButtonId() == R.id.peertube_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "PEERTUBE");
} else if( radioGroup.getCheckedRadioButtonId() == R.id.pixelfed_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "PIXELFED");
} else if( radioGroup.getCheckedRadioButtonId() == R.id.misskey_instance) {
new InstancesDAO(ReorderTimelinesActivity.this, db).insertInstance(instanceName, "MISSKEY");
}
if( timelines != null && adapter != null) {
List<RemoteInstance> instance = new InstancesDAO(ReorderTimelinesActivity.this, db).getInstanceByName(instanceName);
if( instance != null && instance.size() > 0 ) {
ManageTimelines manageTimelines = new ManageTimelines();
manageTimelines.setRemoteInstance(instance.get(0));
manageTimelines.setPosition(timelines.size());
manageTimelines.setDisplayed(true);
manageTimelines.setType(ManageTimelines.Type.INSTANCE);
timelines.add(manageTimelines);
adapter.notifyItemInserted((timelines.size() - 1));
}
updated = true;
}
}
});
} catch (final Exception e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
public void run() {
Toasty.warning(getApplicationContext(), getString(R.string.toast_instance_unavailable), Toast.LENGTH_LONG).show();
}
});
}
}
}).start();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//Hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(instance_list.getWindowToken(), 0);
}
});
if( alertDialog.getWindow() != null )
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
alertDialog.show();
instance_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
String oldSearch = parent.getItemAtPosition(position).toString().trim();
}
});
instance_list.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
Pattern host = Pattern.compile("([\\da-z\\.-]+\\.[a-z\\.]{2,12})");
Matcher matcher = host.matcher(s.toString().trim());
if( s.toString().trim().length() == 0 || !matcher.find()) {
alertDialog.getButton(
AlertDialog.BUTTON_POSITIVE).setEnabled(false);
} else {
// Something into edit text. Enable the button.
alertDialog.getButton(
AlertDialog.BUTTON_POSITIVE).setEnabled(true);
}
if (s.length() > 2 && !isLoadingInstance) {
final String action = "/instances/search";
final HashMap<String, String> parameters = new HashMap<>();
parameters.put("q", s.toString().trim());
parameters.put("count", String.valueOf(1000));
parameters.put("name", String.valueOf(true));
isLoadingInstance = true;
if( oldSearch == null || !oldSearch.equals(s.toString().trim()))
new Thread(new Runnable() {
@Override
public void run() {
try {
final String response = new HttpsConnection(ReorderTimelinesActivity.this).get("https://instances.social/api/1.0" + action, 30, parameters, Helper.THEKINRAR_SECRET_TOKEN);
runOnUiThread(new Runnable() {
public void run() {
isLoadingInstance = false;
String[] instances;
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("instances");
if (jsonArray != null) {
int length = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true"))
length++;
}
instances = new String[length];
int j = 0;
for (int i = 0; i < jsonArray.length(); i++) {
if( !jsonArray.getJSONObject(i).get("name").toString().contains("@") && jsonArray.getJSONObject(i).get("up").toString().equals("true")) {
instances[j] = jsonArray.getJSONObject(i).get("name").toString();
j++;
}
}
} else {
instances = new String[]{};
}
instance_list.setAdapter(null);
ArrayAdapter<String> adapter =
new ArrayAdapter<>(ReorderTimelinesActivity.this, android.R.layout.simple_list_item_1, instances);
instance_list.setAdapter(adapter);
if (instance_list.hasFocus() && !ReorderTimelinesActivity.this.isFinishing())
instance_list.showDropDown();
oldSearch = s.toString().trim();
} catch (JSONException ignored) {
isLoadingInstance = false;
}
}
});
} catch (HttpsConnection.HttpsConnectionException e) {
isLoadingInstance = false;
} catch (Exception e) {
isLoadingInstance = false;
}
}
}).start();
else
isLoadingInstance = false;
}
}
});
}
});
toolbar_title.setText(R.string.action_reorder_timeline);
if (theme == THEME_LIGHT){
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
@ -159,13 +390,18 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
if( actionCanBeApplied){
switch (manageTimelines.getType()){
case TAG:
new SearchDAO(getApplicationContext(), db).remove(manageTimelines.getTagTimeline().getName());
new TimelinesDAO(getApplicationContext(), db).remove(manageTimelines);
new SearchDAO(getApplicationContext(), db).remove(manageTimelines.getTagTimeline().getName());
new TimelinesDAO(getApplicationContext(), db).remove(manageTimelines);
break;
case INSTANCE:
new InstancesDAO(getApplicationContext(), db).remove(manageTimelines.getRemoteInstance().getId());
new TimelinesDAO(getApplicationContext(), db).remove(manageTimelines);
break;
case LIST:
timeline = manageTimelines;
new ManageListsAsyncTask(getApplicationContext(), ManageListsAsyncTask.action.DELETE_LIST,null, null, manageTimelines.getListTimeline().getId(), null, ReorderTimelinesActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new TimelinesDAO(getApplicationContext(), db).remove(timeline);
break;
}
updated = true;
}
@ -195,4 +431,7 @@ public class ReorderTimelinesActivity extends BaseActivity implements OnStartDra
}
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
}
}

View File

@ -16,14 +16,11 @@ package fr.gouv.etalab.mastodon.drawers;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -36,10 +33,7 @@ import java.util.List;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.ListActivity;
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
@ -48,20 +42,16 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
* Created by Thomas on 13/12/2017.
* Adapter for lists
*/
public class ListAdapter extends BaseAdapter implements OnListActionInterface {
public class ListAdapter extends BaseAdapter {
private List<fr.gouv.etalab.mastodon.client.Entities.List> lists;
private LayoutInflater layoutInflater;
private Context context;
private ListAdapter listAdapter;
private RelativeLayout textviewNoAction;
public ListAdapter(Context context, List<fr.gouv.etalab.mastodon.client.Entities.List> lists, RelativeLayout textviewNoAction){
this.lists = lists;
layoutInflater = LayoutInflater.from(context);
this.context = context;
this.listAdapter = this;
this.textviewNoAction = textviewNoAction;
}
@Override
@ -125,51 +115,9 @@ public class ListAdapter extends BaseAdapter implements OnListActionInterface {
context.startActivity(intent);
}
});
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK){
style = R.style.DialogBlack;
}else {
style = R.style.Dialog;
}
holder.search_container.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
builder.setTitle(context.getString(R.string.action_lists_delete) + ": " + list.getTitle());
builder.setMessage(context.getString(R.string.action_lists_confirm_delete) );
builder.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
lists.remove(list);
listAdapter.notifyDataSetChanged();
new ManageListsAsyncTask(context, ManageListsAsyncTask.action.DELETE_LIST,null, null, list.getId(), null, ListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if( lists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
textviewNoAction.setVisibility(View.VISIBLE);
dialog.dismiss();
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
return false;
}
});
return convertView;
}
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
}
private class ViewHolder {
LinearLayout search_container;
TextView search_title;

View File

@ -204,17 +204,13 @@ public class ReorderTabAdapter extends RecyclerView.Adapter<ReorderTabAdapter.It
@Override
public void onItemDismiss(int position) {
ManageTimelines item = mItems.get(position);
if( item.getType() == ManageTimelines.Type.TAG || item.getType() == ManageTimelines.Type.INSTANCE ) {
if( item.getType() == ManageTimelines.Type.TAG || item.getType() == ManageTimelines.Type.INSTANCE || item.getType() == ManageTimelines.Type.LIST) {
mUndoListener.onUndo(item, position);
mItems.remove(position);
notifyItemRemoved(position);
}else{
notifyItemChanged(position);
if( item.getType() == ManageTimelines.Type.LIST ){
Toasty.info(context, context.getString(R.string.warning_list_deletion), Toast.LENGTH_SHORT).show();
}else{
Toasty.info(context, context.getString(R.string.warning_main_timeline), Toast.LENGTH_SHORT).show();
}
Toasty.info(context, context.getString(R.string.warning_main_timeline), Toast.LENGTH_SHORT).show();
}
}

View File

@ -647,20 +647,6 @@ public class SettingsFragment extends Fragment {
});
boolean follow_instance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
final CheckBox set_follow_instance = rootView.findViewById(R.id.set_display_follow_instance);
set_follow_instance.setChecked(follow_instance);
set_follow_instance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, set_follow_instance.isChecked());
editor.apply();
((MainActivity) context).refreshButton();
}
});
boolean display_bookmark = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOKMARK, false);
final CheckBox set_display_bookmark = rootView.findViewById(R.id.set_display_bookmarks);
set_display_bookmark.setChecked(display_bookmark);

View File

@ -207,14 +207,6 @@
/>
</RadioGroup>
<!-- HIDE FOLLOW INSTANCE BUTTON -->
<CheckBox
android:id="@+id/set_display_follow_instance"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/settings_checkbox_margin"
android:layout_marginBottom="@dimen/settings_checkbox_margin"
android:text="@string/set_display_follow_instance"
android:layout_height="wrap_content" />
<!-- DISPLAY NEW BADGE -->
<CheckBox

View File

@ -147,17 +147,6 @@
android:layout_margin="@dimen/fab_margin_floating"
app:srcCompat="@drawable/ic_action_add_new"
tools:ignore="VectorDrawableCompat" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/federated_timeline"
android:layout_width="wrap_content"
android:contentDescription="@string/follow_instance"
android:layout_height="wrap_content"
app:fabSize="mini"
android:layout_gravity="bottom|start"
android:layout_margin="@dimen/fab_margin_floating"
app:srcCompat="@drawable/ic_public_world"
tools:ignore="VectorDrawableCompat" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView

View File

@ -214,14 +214,6 @@
/>
</RadioGroup>
<!-- HIDE FOLLOW INSTANCE BUTTON -->
<CheckBox
android:id="@+id/set_display_follow_instance"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/settings_checkbox_margin"
android:layout_marginBottom="@dimen/settings_checkbox_margin"
android:text="@string/set_display_follow_instance"
android:layout_height="wrap_content" />
<!-- DISPLAY NEW BADGE -->
<CheckBox

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017 Thomas Schneider
This file is a part of Mastalab
This program is free software; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation; either version 3 of the
License, or (at your option) any later version.
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with Mastalab; if not,
see <http://www.gnu.org/licenses>.
-->
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="?attr/popupOverlay"
tools:ignore="UnusedAttribute">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/toolbar_close"
android:src="@drawable/ic_close"
android:layout_width="30dp"
android:layout_height="30dp"
android:gravity="center_vertical"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:contentDescription="@string/close" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:textColor="?attr/actionBarTextColor"
android:textSize="16sp"
android:maxLines="1"
android:id="@+id/toolbar_title" />
<ImageView
android:id="@+id/add_remote_instance"
android:src="@drawable/ic_add"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:contentDescription="@string/add_remote_instance"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>

View File

@ -933,6 +933,7 @@
<string name="warning_list_deletion">Use the lists entry for deleting this list!</string>
<string name="warning_main_timeline">Main timelines can only be hidden!</string>
<string name="action_bbcode">BBCode</string>
<string name="add_timeline">Add a timeline</string>
<plurals name="number_of_vote">
<item quantity="one">%d vote</item>