Improves layout when writing toots (scroll) + allows to open url with an external app when using the built-in browser (via top bar icon)

This commit is contained in:
tom79 2017-07-23 09:45:08 +02:00
parent 8b625a34a9
commit 920cbd6afa
15 changed files with 195 additions and 163 deletions

View File

@ -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)

View File

@ -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

View File

@ -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);
}

View File

@ -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() {

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 985 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -15,178 +15,170 @@
You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="@dimen/toot_padding"
android:paddingRight="@dimen/toot_padding"
android:orientation="vertical">
<EditText
android:id="@+id/toot_cw_content"
android:layout_marginTop="20dp"
android:animateLayoutChanges="true"
android:visibility="gone"
android:maxLines="1"
android:hint="@string/toot_cw_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
>
<LinearLayout
android:id="@+id/toot_reply_content_container"
android:visibility="gone"
android:layout_width="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="@dimen/toot_padding"
android:paddingRight="@dimen/toot_padding"
android:orientation="vertical">
<TextView
android:text="@string/toot_reply_content_title"
<EditText
android:id="@+id/toot_cw_content"
android:layout_marginTop="20dp"
android:animateLayoutChanges="true"
android:visibility="gone"
android:maxLines="1"
android:hint="@string/toot_cw_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
<RelativeLayout
android:id="@+id/toot_reply_content_container"
android:visibility="gone"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/toot_reply_content_title"
android:text="@string/toot_reply_content_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="@+id/toot_reply_content_title"
android:id="@+id/toot_reply_content"
android:layout_marginTop="10dp"
android:gravity="top|start"
android:maxLines="4"
android:textStyle="italic"
android:autoLink="web"
android:layout_width="0dp"
android:layout_weight="1"
android:textSize="12sp"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_reply"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
app:fabSize="mini"
android:layout_margin="@dimen/fab_margin"
android:layout_margin="5dp"
app:srcCompat="@drawable/ic_close" />
</LinearLayout>
</LinearLayout>
<EditText
android:layout_marginTop="10dp"
android:id="@+id/toot_content"
android:gravity="top|start"
android:hint="@string/toot_placeholder"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:padding="5dp"
android:id="@+id/toot_picture_container"
android:layout_width="wrap_content"
</RelativeLayout>
<EditText
android:layout_marginTop="10dp"
android:id="@+id/toot_content"
android:gravity="top|start"
android:inputType="textMultiLine"
android:hint="@string/toot_placeholder"
android:layout_width="match_parent"
android:minLines="4"
android:layout_weight="1"
android:layout_height="0dp" />
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="100dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:orientation="horizontal"
>
<RelativeLayout
android:id="@+id/loading_picture"
android:visibility="gone"
<LinearLayout
android:padding="5dp"
android:id="@+id/toot_picture_container"
android:layout_width="wrap_content"
android:gravity="center"
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"
>
<ProgressBar
android:id="@+id/pbar_inf"
android:id="@+id/loading_picture"
android:visibility="gone"
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminate="true" />
<TextView
android:id="@+id/loader_progress"
android:textSize="12sp"
android:visibility="gone"
android:layout_marginTop="10dp"
android:textColor="?attr/colorAccent"
android:layout_below="@+id/pbar_inf"
android:layout_width="50dp"
android:gravity="center"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<RelativeLayout
android:visibility="gone"
android:id="@+id/toot_show_accounts"
android:maxHeight="300dp"
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_accounts"
<RelativeLayout
android:visibility="gone"
android:id="@+id/toot_show_accounts"
android:maxHeight="300dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
android:id="@+id/toot_close_accounts"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center"
app:fabSize="mini"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_close" />
<ListView
android:id="@+id/toot_lv_accounts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<ImageButton
android:id="@+id/toot_picture"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_action_camera"
/>
<ImageButton
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:id="@+id/toot_visibility"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_globe"
/>
<Button
android:id="@+id/toot_cw"
android:padding="5dp"
android:text="@string/cw"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="@+id/toot_space_left"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center"
app:fabSize="mini"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_close" />
<ListView
android:id="@+id/toot_lv_accounts"
android:layout_height="40dp" />
<Button
android:id="@+id/toot_it"
android:padding="5dp"
android:text="@string/toot_it"
android:layout_gravity="end"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<ImageButton
android:id="@+id/toot_picture"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_camera"
/>
<ImageButton
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:id="@+id/toot_visibility"
android:padding="5dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_action_globe"
/>
<Button
android:id="@+id/toot_cw"
android:padding="5dp"
android:text="@string/cw"
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="@+id/toot_space_left"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center"
android:layout_height="40dp" />
<Button
android:id="@+id/toot_it"
android:padding="5dp"
android:text="@string/toot_it"
android:layout_gravity="end"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<CheckBox
android:text="@string/toot_sensitive"
android:visibility="gone"
android:id="@+id/toot_sensitive"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<CheckBox
android:text="@string/toot_sensitive"
android:visibility="gone"
android:id="@+id/toot_sensitive"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_go"
android:title="@string/open_with"
android:icon="@drawable/ic_action_goright"
app:showAsAction="always" />
</menu>

View File

@ -46,6 +46,7 @@
<string name="schedule">Programmer</string>
<string name="next">Suivant</string>
<string name="previous">Précédent</string>
<string name="open_with">Ouvrir avec</string>
<!--- Menu -->
<string name="home_menu">Accueil</string>
<string name="local_menu">Fil public local</string>

View File

@ -49,6 +49,7 @@
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="open_with">Open with</string>
<!--- Menu -->
<string name="home_menu">Home</string>
<string name="local_menu">Local timeline</string>