Some fixes

This commit is contained in:
tom79 2017-09-23 18:27:45 +02:00
parent f095922970
commit 5aeffb8ad7
6 changed files with 59 additions and 70 deletions

View File

@ -109,7 +109,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.changeHamburgerIcon;
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
@ -406,8 +405,17 @@ public class MainActivity extends AppCompatActivity
startActivity(intent);
toolbar_search.setQuery("", false);
toolbar_search.setIconified(true);
toolbarTitle.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
if( main_app_container.getVisibility() == View.VISIBLE){
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
}else {
main_app_container.setVisibility(View.GONE);
viewPager.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
toolbarTitle.setVisibility(View.GONE);
}
return false;
}
@Override
@ -496,15 +504,12 @@ public class MainActivity extends AppCompatActivity
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(false);
changeHamburgerIcon(MainActivity.this, account.getAvatar(), toggle);
changeHamburgerIcon(MainActivity.this, account.getAvatar());
toggle.syncState();
headerLayout = navigationView.getHeaderView(0);
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
loadPPInActionBar(MainActivity.this, account.getAvatar());
//Locked account can see follow request
if (account.isLocked()) {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);

View File

@ -20,6 +20,8 @@ package fr.gouv.etalab.mastodon.helper;
import android.app.Activity;
import android.graphics.Color;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.RequiresApi;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AlertDialog;
@ -959,12 +961,26 @@ public class Helper {
}
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,int roundPixelSize) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = roundPixelSize;
paint.setAntiAlias(true);
canvas.drawRoundRect(rectF,roundPx,roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
/**
* Load the profile picture at the place of hamburger icon
* @param activity Activity The current activity
* @param url String the url of the profile picture
*/
public static void changeHamburgerIcon(final Activity activity, String url, ActionBarDrawerToggle toggle){
public static void changeHamburgerIcon(final Activity activity, String url){
ImageLoader imageLoader;
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
@ -977,8 +993,8 @@ public class Helper {
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
Resources res = activity.getResources();
Bitmap loadedImageResized = Bitmap.createScaledBitmap(loadedImage, (int)convertDpToPixel(30, activity), (int)convertDpToPixel(30, activity), true);
BitmapDrawable icon = new BitmapDrawable(res, loadedImageResized);
Bitmap loadedImageResized = Bitmap.createScaledBitmap(loadedImage, (int)convertDpToPixel(40, activity), (int)convertDpToPixel(40, activity), true);
BitmapDrawable icon = new BitmapDrawable(res, getRoundedCornerBitmap(loadedImageResized, 90));
if( ((MainActivity)activity).getSupportActionBar() != null)
((MainActivity)activity).getSupportActionBar().setIcon(icon);
}

View File

@ -22,6 +22,7 @@ import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import org.json.JSONException;

View File

@ -1,41 +0,0 @@
<?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>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="@+id/tab_icon"
android:layout_gravity="center"
android:layout_width="30dp"
android:layout_height="30dp" />
<TextView
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:id="@+id/tab_counter"
android:visibility="gone"
android:gravity="center"
android:textSize="14sp"
android:minWidth="30dp"
android:minHeight="30dp"
android:textColor="@color/mastodonC1"
android:background="@drawable/shape_counter"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View File

@ -15,27 +15,30 @@
You should have received a copy of the GNU General Public License along with Mastalab; if not,
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical">
<ImageView
android:id="@+id/tab_icon"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:id="@+id/tab_counter"
android:visibility="gone"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:textSize="10sp"
android:minWidth="20dp"
android:minHeight="20dp"
android:textSize="12sp"
android:textColor="@color/mastodonC1"
android:background="@drawable/shape_counter"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ImageView
android:id="@+id/tab_icon"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@ -111,7 +111,6 @@ import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.changeHamburgerIcon;
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
@ -410,8 +409,17 @@ public class MainActivity extends AppCompatActivity
startActivity(intent);
toolbar_search.setQuery("", false);
toolbar_search.setIconified(true);
toolbarTitle.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
if( main_app_container.getVisibility() == View.VISIBLE){
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
toolbarTitle.setVisibility(View.VISIBLE);
}else {
main_app_container.setVisibility(View.GONE);
viewPager.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
toolbarTitle.setVisibility(View.GONE);
}
return false;
}
@Override
@ -500,15 +508,12 @@ public class MainActivity extends AppCompatActivity
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.setDrawerIndicatorEnabled(false);
changeHamburgerIcon(MainActivity.this, account.getAvatar(), toggle);
changeHamburgerIcon(MainActivity.this, account.getAvatar());
toggle.syncState();
headerLayout = navigationView.getHeaderView(0);
updateHeaderAccountInfo(MainActivity.this, account, headerLayout, imageLoader, options);
loadPPInActionBar(MainActivity.this, account.getAvatar());
//Locked account can see follow request
if (account.isLocked()) {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);