diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java index 9d9d73bd1..5ecdba9c8 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/MainActivity.java @@ -369,21 +369,17 @@ public class MainActivity extends AppCompatActivity String userIdIntent; boolean matchingIntent = false; if( extras.containsKey(INTENT_ACTION) ){ - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); //Id of the authenticated account final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){ - if( userId!= null && !userId.equals(userIdIntent)) //Connected account is different from the id in the intent - changeUser(MainActivity.this, userIdIntent); //Connects the account which is related to the notification + changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification unCheckAllMenuItems(navigationView.getMenu()); navigationView.getMenu().performIdentifierAction(R.id.nav_notification, 0); if( navigationView.getMenu().findItem(R.id.nav_notification) != null) navigationView.getMenu().findItem(R.id.nav_notification).setChecked(true); matchingIntent = true; }else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){ - if( userId!= null && !userId.equals(userIdIntent)) //Connected account is different from the id in the intent - changeUser(MainActivity.this, userIdIntent); //Connects the account which is related to the notification + changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification unCheckAllMenuItems(navigationView.getMenu()); navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0); if( navigationView.getMenu().findItem(R.id.nav_home) != null) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 6c10f1592..683318de4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -43,6 +43,7 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; @@ -56,6 +57,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.TimePicker; @@ -121,7 +123,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc private int maxChar; private String visibility; private final int PICK_IMAGE = 56556; - private RelativeLayout loading_picture; + private ProgressBar loading_picture; private ImageButton toot_picture; private ImageLoader imageLoader; private DisplayImageOptions options; @@ -132,7 +134,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc private Button toot_it; private EditText toot_content, toot_cw_content; private TextView toot_reply_content; - private LinearLayout toot_reply_content_container; + private RelativeLayout toot_reply_content_container; private RelativeLayout toot_show_accounts; private ListView toot_lv_accounts; private BroadcastReceiver search_validate; @@ -144,8 +146,6 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc private TextView title; private ImageView pp_actionBar; - private String pattern = "^(.|\\s)*(@([a-zA-Z0-9_]{2,}))$"; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -190,12 +190,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc final TextView toot_space_left = (TextView) findViewById(R.id.toot_space_left); toot_visibility = (ImageButton) findViewById(R.id.toot_visibility); toot_picture = (ImageButton) findViewById(R.id.toot_picture); - loading_picture = (RelativeLayout) findViewById(R.id.loading_picture); + loading_picture = (ProgressBar) findViewById(R.id.loading_picture); toot_picture_container = (LinearLayout) findViewById(R.id.toot_picture_container); toot_content = (EditText) findViewById(R.id.toot_content); toot_cw_content = (EditText) findViewById(R.id.toot_cw_content); toot_reply_content = (TextView) findViewById(R.id.toot_reply_content); - toot_reply_content_container = (LinearLayout) findViewById(R.id.toot_reply_content_container); + toot_reply_content_container = (RelativeLayout) findViewById(R.id.toot_reply_content_container); toot_show_accounts = (RelativeLayout) findViewById(R.id.toot_show_accounts); toot_lv_accounts = (ListView) findViewById(R.id.toot_lv_accounts); toot_sensitive = (CheckBox) findViewById(R.id.toot_sensitive); @@ -406,7 +406,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc } }); - + String pattern = "^(.|\\s)*(@([a-zA-Z0-9_]{2,}))$"; + final Pattern sPattern = Pattern.compile(pattern); toot_content.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @@ -415,8 +416,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc @Override public void afterTextChanged(Editable s) { - Pattern sPattern = Pattern.compile(pattern); - Matcher m = sPattern.matcher(s.toString()); + int length; + //Only check last 20 characters to avoid lags + if( s.toString().length() < 20 ){ //Less than 20 characters are written + length = s.toString().length(); + }else { + length = 20; + } + Matcher m = sPattern.matcher(s.toString().substring(s.toString().length()- length, s.toString().length())); if(m.matches()) { String search = m.group(3); new RetrieveSearchAccountsAsyncTask(getApplicationContext(),search,TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -434,6 +441,21 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc toot_space_left.setText(String.valueOf((maxChar - totalChar))); } }); + //Allow scroll of the EditText though it's embedded in a scrollview + toot_content.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (v.getId() == R.id.toot_content) { + v.getParent().requestDisallowInterceptTouchEvent(true); + switch (event.getAction() & MotionEvent.ACTION_MASK) { + case MotionEvent.ACTION_UP: + v.getParent().requestDisallowInterceptTouchEvent(false); + break; + } + } + return false; + } + }); toot_cw_content.addTextChangedListener(new TextWatcher() { @Override diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java index 468b07bed..cef7813f5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java @@ -16,14 +16,17 @@ package fr.gouv.etalab.mastodon.activities; import android.Manifest; +import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.util.Log; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -119,12 +122,21 @@ public class WebviewActivity extends AppCompatActivity { webView.loadUrl(url); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_webview, menu); + return true; + } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish(); return true; + case R.id.action_go: + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + startActivity(browserIntent); + return true; default: return super.onOptionsItemSelected(item); } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 918a36821..d03b36d85 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -210,9 +210,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf public void onClick(View v) { try { if( !status.isTranslated() ){ - //new YandexQuery(StatusListAdapter.this).getYandexTextview(position, status.getContent(), currentLocale); new YandexQuery(StatusListAdapter.this).getYandexTextview(position, status.getContent(), currentLocale); - }else { status.setTranslationShown(!status.isTranslationShown()); statusListAdapter.notifyDataSetChanged(); @@ -272,7 +270,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf changeDrawableColor(context, R.drawable.ic_translate,R.color.black); } - + //Redraws top icons (boost/reply) final float scale = context.getResources().getDisplayMetrics().density; if( !status.getIn_reply_to_account_id().equals("null") || !status.getIn_reply_to_id().equals("null") ){ Drawable img = ContextCompat.getDrawable(context, R.drawable.ic_reply); @@ -286,7 +284,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf holder.status_account_displayname.setCompoundDrawables( null, null, null, null); } - //Click on a conversation if( type != RetrieveFeedsAsyncTask.Type.CONTEXT ){ holder.status_content.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index f2413e377..24cf3282b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -776,7 +776,7 @@ public class Helper { menuAccountsOpened = false; String userId = account.getId(); Toast.makeText(activity, activity.getString(R.string.toast_account_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_LONG).show(); - changeUser(activity, userId); + changeUser(activity, userId, true); arrow.setImageResource(R.drawable.ic_arrow_drop_down); return true; } @@ -846,13 +846,15 @@ public class Helper { * @param activity Activity * @param userID String - the new user id */ - public static void changeUser(Activity activity, String userID) { + public static void changeUser(Activity activity, String userID, boolean checkItem) { final NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view); navigationView.getMenu().clear(); navigationView.inflateMenu(R.menu.activity_main_drawer); - navigationView.setCheckedItem(R.id.nav_home); - navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0); + if( checkItem ) { + navigationView.setCheckedItem(R.id.nav_home); + navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0); + } SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); Account account = new AccountDAO(activity,db).getAccountByID(userID); //Can happen when an account has been deleted and there is a click on an old notification diff --git a/app/src/main/res/drawable-hdpi/ic_action_goright.png b/app/src/main/res/drawable-hdpi/ic_action_goright.png new file mode 100644 index 000000000..60bfa25ed Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_action_goright.png differ diff --git a/app/src/main/res/drawable-ldpi/ic_action_goright.png b/app/src/main/res/drawable-ldpi/ic_action_goright.png new file mode 100644 index 000000000..70abf490b Binary files /dev/null and b/app/src/main/res/drawable-ldpi/ic_action_goright.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_action_goright.png b/app/src/main/res/drawable-mdpi/ic_action_goright.png new file mode 100644 index 000000000..e5b64b33d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_action_goright.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_action_goright.png b/app/src/main/res/drawable-xhdpi/ic_action_goright.png new file mode 100644 index 000000000..feb471b2b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_action_goright.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_goright.png b/app/src/main/res/drawable-xxhdpi/ic_action_goright.png new file mode 100644 index 000000000..8937a7d7e Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_action_goright.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_action_goright.png b/app/src/main/res/drawable-xxxhdpi/ic_action_goright.png new file mode 100644 index 000000000..f73b8bd72 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_action_goright.png differ diff --git a/app/src/main/res/layout/activity_toot.xml b/app/src/main/res/layout/activity_toot.xml index c7448e0a7..e103b72ce 100644 --- a/app/src/main/res/layout/activity_toot.xml +++ b/app/src/main/res/layout/activity_toot.xml @@ -15,178 +15,170 @@ You should have received a copy of the GNU General Public License along with Thomas Schneider; if not, see . --> - - - + > - - + android:layout_height="wrap_content" + > + - - - - - - + + - + android:layout_height="wrap_content" + android:maxHeight="100dp" + android:layout_gravity="center_vertical" + android:gravity="center_vertical" + android:orientation="horizontal" + > - - - - - - + + - + + + + + +