Remote instance follow - step2
This commit is contained in:
parent
57d30a3f2e
commit
071136a7aa
|
@ -23,6 +23,7 @@ import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.AppBarLayout;
|
import android.support.design.widget.AppBarLayout;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
@ -32,12 +33,15 @@ import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.support.v4.view.GravityCompat;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputFilter;
|
import android.text.InputFilter;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
@ -64,6 +68,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||||
import fr.gouv.etalab.mastodon.client.HttpsConnection;
|
import fr.gouv.etalab.mastodon.client.HttpsConnection;
|
||||||
|
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.services.LiveNotificationService;
|
import fr.gouv.etalab.mastodon.services.LiveNotificationService;
|
||||||
|
@ -144,15 +149,7 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
|
||||||
String instanceName = instance_list.getText().toString().trim();
|
String instanceName = instance_list.getText().toString().trim();
|
||||||
//Already in db
|
|
||||||
List<String> s_ = new InstancesDAO(InstanceFederatedActivity.this, db).getInstanceByName(instanceName);
|
|
||||||
if( s_ == null)
|
|
||||||
s_ = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
new Thread(new Runnable(){
|
new Thread(new Runnable(){
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -161,16 +158,21 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
JSONObject resobj;
|
JSONObject resobj;
|
||||||
try {
|
dialog.dismiss();
|
||||||
new InstancesDAO(InstanceFederatedActivity.this, db).insertInstance(instanceName);
|
new InstancesDAO(InstanceFederatedActivity.this, db).insertInstance(instanceName);
|
||||||
|
|
||||||
resobj = new JSONObject(response);
|
Helper.addTab(tabLayout, adapter, instanceName);
|
||||||
Intent intent = new Intent(InstanceFederatedActivity.this, InstanceFederatedActivity.class);
|
adapter = new InstanceFederatedActivity.PagerAdapter
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
(getSupportFragmentManager(), tabLayout.getTabCount());
|
||||||
intent.putExtra(INTENT_ACTION, SEARCH_INSTANCE);
|
viewPager.setAdapter(adapter);
|
||||||
intent.putExtra(INSTANCE_NAME, instanceName);
|
for(int i = 0; i < tabLayout.getTabCount() ; i++ ){
|
||||||
startActivity(intent);
|
if( tabLayout.getTabAt(i).getText() != null && tabLayout.getTabAt(i).getText().equals(instanceName.trim())){
|
||||||
} catch (JSONException ignored) {ignored.printStackTrace();}
|
tabLayout.getTabAt(i).select();
|
||||||
|
attacheDelete(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
@ -324,11 +326,6 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
tabLayout.setTabMode(TabLayout.MODE_FIXED);
|
tabLayout.setTabMode(TabLayout.MODE_FIXED);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Display filter for notification when long pressing the tab
|
|
||||||
final LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
|
|
||||||
|
|
||||||
|
|
||||||
viewPager = findViewById(R.id.viewpager);
|
viewPager = findViewById(R.id.viewpager);
|
||||||
|
|
||||||
adapter = new PagerAdapter
|
adapter = new PagerAdapter
|
||||||
|
@ -336,11 +333,27 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
viewPager.setAdapter(adapter);
|
viewPager.setAdapter(adapter);
|
||||||
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||||
|
|
||||||
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||||
|
@Override
|
||||||
|
public void onTabSelected(TabLayout.Tab tab) {
|
||||||
|
viewPager.setCurrentItem(tab.getPosition());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onTabUnselected(TabLayout.Tab tab) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onTabReselected(TabLayout.Tab tab) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
refreshInstanceTab();
|
refreshInstanceTab();
|
||||||
|
|
||||||
|
int tabCount = tabLayout.getTabCount();
|
||||||
|
for( int j = 0 ; j < tabCount ; j++){
|
||||||
|
attacheDelete(j);
|
||||||
|
}
|
||||||
|
|
||||||
//Hide the default title
|
//Hide the default title
|
||||||
if( getSupportActionBar() != null) {
|
if( getSupportActionBar() != null) {
|
||||||
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
||||||
|
@ -401,6 +414,65 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void attacheDelete(int position){
|
||||||
|
LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0);
|
||||||
|
String title = tabLayout.getTabAt(position).getText().toString().trim();
|
||||||
|
SQLiteDatabase db = Sqlite.getInstance(InstanceFederatedActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
tabStrip.getChildAt(position).setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(InstanceFederatedActivity.this);
|
||||||
|
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
new InstancesDAO(InstanceFederatedActivity.this, db).remove(title);
|
||||||
|
String instanceName;
|
||||||
|
if( position > 0)
|
||||||
|
instanceName = tabLayout.getTabAt(position -1).getText().toString();
|
||||||
|
else if( tabLayout.getTabCount() > 1 )
|
||||||
|
instanceName = tabLayout.getTabAt(1).getText().toString();
|
||||||
|
else //Last element
|
||||||
|
instanceName = "";
|
||||||
|
Helper.removeTab(tabLayout, adapter, position);
|
||||||
|
adapter = new InstanceFederatedActivity.PagerAdapter
|
||||||
|
(getSupportFragmentManager(), tabLayout.getTabCount());
|
||||||
|
viewPager.setAdapter(adapter);
|
||||||
|
for(int i = 0; i < tabLayout.getTabCount() ; i++ ){
|
||||||
|
if( tabLayout.getTabAt(i).getText() != null && tabLayout.getTabAt(i).getText().equals(instanceName.trim())){
|
||||||
|
tabLayout.getTabAt(i).select();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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.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(viewPager.getWindowToken(), 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if( alertDialog.getWindow() != null )
|
||||||
|
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||||
|
alertDialog.show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
|
@ -2188,8 +2188,7 @@ public class Helper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeSearchTab(String keyword, TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter){
|
public static void removeInstanceTab(String keyword, TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter){
|
||||||
|
|
||||||
int selection = -1;
|
int selection = -1;
|
||||||
for(int i = 0; i < tableLayout.getTabCount() ; i++ ){
|
for(int i = 0; i < tableLayout.getTabCount() ; i++ ){
|
||||||
if( tableLayout.getTabAt(i).getText() != null && tableLayout.getTabAt(i).getText().equals(keyword)) {
|
if( tableLayout.getTabAt(i).getText() != null && tableLayout.getTabAt(i).getText().equals(keyword)) {
|
||||||
|
@ -2201,14 +2200,15 @@ public class Helper {
|
||||||
removeTab(tableLayout, pagerAdapter, selection);
|
removeTab(tableLayout, pagerAdapter, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void removeTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, int position) {
|
public static void removeTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, int position) {
|
||||||
if (tableLayout.getTabCount() >= position) {
|
if (tableLayout.getTabCount() >= position ) {
|
||||||
tableLayout.removeTabAt(position);
|
if(tableLayout.getTabCount() > 0)
|
||||||
|
tableLayout.removeTabAt(position);
|
||||||
pagerAdapter.removeTabPage();
|
pagerAdapter.removeTabPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, String title) {
|
public static void addTab(TabLayout tableLayout, InstanceFederatedActivity.PagerAdapter pagerAdapter, String title) {
|
||||||
tableLayout.addTab(tableLayout.newTab().setText(title));
|
tableLayout.addTab(tableLayout.newTab().setText(title));
|
||||||
pagerAdapter.addTabPage(title);
|
pagerAdapter.addTabPage(title);
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class InstancesDAO {
|
||||||
*/
|
*/
|
||||||
public void insertInstance(String instanceName) {
|
public void insertInstance(String instanceName) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Sqlite.COL_INSTANCE, instanceName);
|
values.put(Sqlite.COL_INSTANCE, instanceName.trim());
|
||||||
values.put(Sqlite.COL_USER_ID, userId);
|
values.put(Sqlite.COL_USER_ID, userId);
|
||||||
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(new Date()));
|
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(new Date()));
|
||||||
//Inserts search
|
//Inserts search
|
||||||
|
|
|
@ -545,6 +545,8 @@
|
||||||
<string name="alert_regex">There is an error in the regular expression!</string>
|
<string name="alert_regex">There is an error in the regular expression!</string>
|
||||||
<string name="no_account_yet">No account yet?</string>
|
<string name="no_account_yet">No account yet?</string>
|
||||||
<string name="toast_instance_unavailable">No timelines was found on this instance!</string>
|
<string name="toast_instance_unavailable">No timelines was found on this instance!</string>
|
||||||
|
<string name="delete_instance">Delete this instance?</string>
|
||||||
|
<string name="warning_delete_instance">You are going to delete %s from your followed instances.</string>
|
||||||
<string-array translatable="false" name="proxy_type_choice">
|
<string-array translatable="false" name="proxy_type_choice">
|
||||||
<item>HTTP</item>
|
<item>HTTP</item>
|
||||||
<item>SOCKS</item>
|
<item>SOCKS</item>
|
||||||
|
|
Loading…
Reference in New Issue