Skip to content

Commit

Permalink
clean up frame navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 3, 2019
1 parent aa81e91 commit 2e73d1f
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 26 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/co/tinode/tindroid/ChatsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

Fragment fragment = new ChatsFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.contentFragment, new ChatsFragment(), FRAGMENT_CHATLIST)
.replace(R.id.contentFragment, fragment, FRAGMENT_CHATLIST)
.setPrimaryNavigationFragment(fragment)
.commit();

mMeTopic = Cache.getTinode().getOrCreateMeTopic();
Expand Down Expand Up @@ -139,7 +141,10 @@ void showFragment(String tag) {
}
}

trx.addToBackStack(tag).replace(R.id.contentFragment, fragment, tag).commit();
trx.replace(R.id.contentFragment, fragment, tag)
.addToBackStack(tag)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit();
}

// This is called on Websocket thread.
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/co/tinode/tindroid/ChatsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
((Toolbar) activity.findViewById(R.id.toolbar)).setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// activity.getSupportFragmentManager().popBackStack();
((ChatsActivity)activity).showFragment(ChatsActivity.FRAGMENT_CHATLIST);
activity.getSupportFragmentManager().popBackStack();
}
});
}
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/co/tinode/tindroid/ImageViewFragment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package co.tinode.tindroid;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand All @@ -12,6 +13,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


/**
Expand All @@ -26,6 +28,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
return inflater.inflate(R.layout.fragment_view_image, container, false);
}


@SuppressLint("SetTextI18n")
@Override
public void onResume() {
super.onResume();
Expand All @@ -39,7 +43,11 @@ public void onResume() {
byte[] bits = bundle.getByteArray("image");
if (bits != null) {
Bitmap bmp = BitmapFactory.decodeByteArray(bits, 0, bits.length);
((ImageView) getActivity().findViewById(R.id.image)).setImageDrawable(new BitmapDrawable(getResources(), bmp));
String size = bmp.getWidth() + " \u00D7 " + bmp.getHeight() + "; ";
((ImageView) activity.findViewById(R.id.image)).setImageDrawable(new BitmapDrawable(getResources(), bmp));
((TextView) activity.findViewById(R.id.content_type)).setText(bundle.getString("mime"));
((TextView) activity.findViewById(R.id.file_name)).setText(bundle.getString("name"));
((TextView) activity.findViewById(R.id.image_size)).setText(size + UiUtils.bytesToHumanSize(bits.length));
}
}
}
10 changes: 7 additions & 3 deletions app/src/main/java/co/tinode/tindroid/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;
import androidx.appcompat.widget.Toolbar;
import android.text.TextUtils;
Expand Down Expand Up @@ -97,7 +98,8 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showFragment(FRAGMENT_LOGIN);
getSupportFragmentManager().popBackStack();
//showFragment(FRAGMENT_LOGIN);
}
});

Expand Down Expand Up @@ -282,8 +284,10 @@ private void showFragment(String tag, Bundle args) {
}

fm.beginTransaction()
.replace(R.id.contentFragment, fragment)
.commit();
.replace(R.id.contentFragment, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.addToBackStack(null)
.commit();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public void onPause() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference preference = findPreference(key);
if (preference == null) {
return;
}

if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
int prefIndex = listPreference.findIndexOfValue(sharedPreferences.getString(key, ""));
Expand Down
28 changes: 16 additions & 12 deletions app/src/main/java/co/tinode/tindroid/MessageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class MessageActivity extends AppCompatActivity {
static final String FRAGMENT_MESSAGES = "msg";
static final String FRAGMENT_INVALID ="invalid";
static final String FRAGMENT_INFO = "info";
static final String FRAGMENT_ADD_TOPIC = "add_topic";
static final String FRAGMENT_EDIT_MEMBERS = "edit_members";
static final String FRAGMENT_VIEW_IMAGE ="view_image";

Expand Down Expand Up @@ -100,15 +99,26 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isFragmentVisible(FRAGMENT_MESSAGES) || isFragmentVisible(FRAGMENT_INVALID)) {
Intent intent = new Intent(MessageActivity.this, ChatsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
} else {
getSupportFragmentManager().popBackStack();
}
/*
if (isFragmentVisible(FRAGMENT_EDIT_MEMBERS)) {
showFragment(FRAGMENT_INFO, false, null);
getSupportFragmentManager().popBackStack();
//showFragment(FRAGMENT_INFO, false, null);
} else if (!isFragmentVisible(FRAGMENT_MESSAGES) && !isFragmentVisible(FRAGMENT_INVALID)) {
showFragment(FRAGMENT_MESSAGES, false, null);
getSupportFragmentManager().popBackStack();
//showFragment(FRAGMENT_MESSAGES, false, null);
} else {
Intent intent = new Intent(MessageActivity.this, ChatsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
}
*/
}
});

Expand Down Expand Up @@ -291,10 +301,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
showFragment(FRAGMENT_INFO, true, null);
return true;
}
case R.id.action_topic_edit: {
showFragment(FRAGMENT_ADD_TOPIC, true, null);
return true;
}
default:
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -357,9 +363,6 @@ void showFragment(String tag, boolean addToBackstack, Bundle args) {
case FRAGMENT_INFO:
fragment = new TopicInfoFragment();
break;
case FRAGMENT_ADD_TOPIC:
fragment = new CreateGroupFragment();
break;
case FRAGMENT_EDIT_MEMBERS:
fragment = new EditMembersFragment();
break;
Expand All @@ -385,8 +388,9 @@ void showFragment(String tag, boolean addToBackstack, Bundle args) {
}

if (!fragment.isVisible()) {
FragmentTransaction trx = fm.beginTransaction();
trx.replace(R.id.contentFragment, fragment, tag);
FragmentTransaction trx = fm.beginTransaction()
.replace(R.id.contentFragment, fragment, tag)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
if (addToBackstack) {
trx.addToBackStack(tag);
}
Expand Down
89 changes: 83 additions & 6 deletions app/src/main/res/layout/fragment_view_image.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
xmlns:tools="http://schemas.android.com/tools">
android:orientation="vertical">

<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/annotation"
android:adjustViewBounds="true"
android:contentDescription=""
tools:src="@drawable/logo_src"
tools:ignore="ContentDescription"/>
android:scaleType="fitCenter"
tools:ignore="ContentDescription"
tools:src="@drawable/logo_src"/>

<LinearLayout
android:id="@+id/annotation"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/file_name_label"
android:textStyle="bold"/>

<TextView
android:id="@+id/file_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
tools:text="some_image.png"/>
</LinearLayout>

<Space
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/content_type_label"
android:textStyle="bold"/>

<TextView
android:id="@+id/content_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
tools:text="image/png"/>
</LinearLayout>

<Space
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/image_size_label"
android:textStyle="bold"/>

<TextView
android:id="@+id/image_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
tools:text="250 \u00D7 198; 256KB"/>
</LinearLayout>
</LinearLayout>

</RelativeLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,8 @@
<string name="id_required">ID is required</string>
<string name="settings">Settings</string>
<string name="no_results">No results</string>
<string name="file_name_label">File name:</string>
<string name="content_type_label">Content type:</string>
<string name="image_size_label">Size:</string>

</resources>

0 comments on commit 2e73d1f

Please sign in to comment.