Skip to content

Commit

Permalink
Added message width adjust and single choose bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
tretdm committed Feb 7, 2023
1 parent 95dd191 commit ef2a4f9
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,57 +341,61 @@ public void onClick(View v) {
}

private void setMonetTheme() {
if(Global.checkMonet(this)) {
MaterialToolbar toolbar = findViewById(R.id.app_toolbar);
if(!isDarkTheme) {
toolbar.setBackgroundColor(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(600)).toLinearSrgb().toSrgb().quantize8());
drawer.setStatusBarBackgroundColor(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(700)).toLinearSrgb().toSrgb().quantize8());
}
int colorOnSurface = MaterialColors.getColor(this, com.google.android.material.R.attr.colorOnSurface, Color.BLACK);
NavigationView navView = findViewById(R.id.nav_view);
int[][] states = new int[][] {
new int[] { android.R.attr.state_checked}, new int[] { }
};
int[] colors;
if(isDarkTheme) {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
} else {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
}
ColorStateList csl = new ColorStateList(states, colors);
navView.setItemIconTintList(csl);
navView.setItemTextColor(csl);

BottomNavigationView b_navView = findViewById(R.id.bottom_nav_view);
if(isDarkTheme) {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
} else {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
try {
if (Global.checkMonet(this)) {
MaterialToolbar toolbar = findViewById(R.id.app_toolbar);
if (!isDarkTheme) {
toolbar.setBackgroundColor(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(600)).toLinearSrgb().toSrgb().quantize8());
drawer.setStatusBarBackgroundColor(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(700)).toLinearSrgb().toSrgb().quantize8());
}
int colorOnSurface = MaterialColors.getColor(this, com.google.android.material.R.attr.colorOnSurface, Color.BLACK);
NavigationView navView = findViewById(R.id.nav_view);
int[][] states = new int[][]{
new int[]{android.R.attr.state_checked}, new int[]{}
};
int[] colors;
if (isDarkTheme) {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
} else {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
}
ColorStateList csl = new ColorStateList(states, colors);
navView.setItemIconTintList(csl);
navView.setItemTextColor(csl);

BottomNavigationView b_navView = findViewById(R.id.bottom_nav_view);
if (isDarkTheme) {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
} else {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
}
csl = new ColorStateList(states, colors);
b_navView.setItemTextColor(csl);
b_navView.setItemIconTintList(csl);
b_navView.setItemRippleColor(ColorStateList.valueOf(getMonet().getPrimaryColor(this, isDarkTheme)));
FloatingActionButton fab = findViewById(R.id.fab_newpost);
if (isDarkTheme) {
fab.setBackgroundTintList(ColorStateList.valueOf(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(600)).toLinearSrgb().toSrgb().quantize8()));
} else {
fab.setBackgroundTintList(ColorStateList.valueOf(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8()));
}
fab.setImageTintList(ColorStateList.valueOf(getMonet().getAccentColor(this, isDarkTheme)));
fab.setRippleColor(ColorStateList.valueOf(getMonet().getPrimaryColor(this, isDarkTheme)));
}
csl = new ColorStateList(states, colors);
b_navView.setItemTextColor(csl);
b_navView.setItemIconTintList(csl);
b_navView.setItemRippleColor(ColorStateList.valueOf(getMonet().getPrimaryColor(this, isDarkTheme)));
FloatingActionButton fab = findViewById(R.id.fab_newpost);
if(isDarkTheme) {
fab.setBackgroundTintList(ColorStateList.valueOf(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(600)).toLinearSrgb().toSrgb().quantize8()));
} else {
fab.setBackgroundTintList(ColorStateList.valueOf(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8()));
}
fab.setImageTintList(ColorStateList.valueOf(getMonet().getAccentColor(this, isDarkTheme)));
fab.setRippleColor(ColorStateList.valueOf(getMonet().getPrimaryColor(this, isDarkTheme)));
} catch (Exception ex) {
ex.printStackTrace();
}
}

Expand Down Expand Up @@ -867,8 +871,12 @@ public void recreate() {

@Override
public void onMonetColorsChanged(@NonNull MonetCompat monet, @NonNull ColorScheme monetColors, boolean isInitialChange) {
super.onMonetColorsChanged(monet, monetColors, isInitialChange);
getMonet().updateMonetColors();
setMonetTheme();
try {
super.onMonetColorsChanged(monet, monetColors, isInitialChange);
getMonet().updateMonetColors();
setMonetTheme();
} catch (Exception ex){
ex.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setAPIWrapper();
createFragments();
setAppBar();
setMonetTheme();
} catch (Exception ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package uk.openvk.android.refresh.user_interface.layouts;

import android.content.Context;
import android.text.Layout;
import android.util.AttributeSet;

public class TightTextView extends androidx.appcompat.widget.AppCompatTextView {
public TightTextView(Context context) {
super(context);
}

public TightTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public TightTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

int specModeW = MeasureSpec.getMode(widthMeasureSpec);
if (specModeW != MeasureSpec.EXACTLY) {
Layout layout = getLayout();
if (layout != null) {
int w = (int) Math.ceil(getMaxLineWidth(layout)) + getCompoundPaddingLeft() + getCompoundPaddingRight();
if (w < getMeasuredWidth()) {
super.onMeasure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.AT_MOST),
heightMeasureSpec);
}
}
}
}

private float getMaxLineWidth(Layout layout) {
float max_width = 0.0f;
int lines = layout.getLineCount();
for (int i = 0; i < lines; i++) {
if (layout.getLineWidth(i) > max_width) {
max_width = layout.getLineWidth(i);
}
}
return max_width;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void onClick(View v) {
if(frg != null) {
if(dlgBuilder != null) {
dlgBuilder.clearCheck(checkedItem);
checkedItem = position;
checkedTv.setChecked(true);
}
((PersonalizationFragment) frg).onMenuItemClicked(list, position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.card.MaterialCardView;
import com.google.android.material.color.MaterialColors;
import com.kieronquinn.monetcompat.core.MonetCompat;

import java.util.ArrayList;
import java.util.Objects;

import uk.openvk.android.refresh.Global;
import uk.openvk.android.refresh.R;
Expand Down Expand Up @@ -54,20 +63,36 @@ public int getItemCount() {
public class Holder extends RecyclerView.ViewHolder {
private final View convertView;
private final TextView msg_text;
private final TextView msg_text_2;
private final TextView msg_timestamp;
private final TextView msg_timestamp_2;
private final LinearLayout horizontal_layout;
private final LinearLayout vertical_layout;

public Holder(View view) {
super(view);
this.convertView = view;
this.horizontal_layout = (LinearLayout) view.findViewById(R.id.text_layout_horizontal);
this.vertical_layout = (LinearLayout) view.findViewById(R.id.text_layout_vertical);
this.msg_text = (TextView) view.findViewById(R.id.msg_text);
this.msg_timestamp = (TextView) view.findViewById(R.id.timestamp);
this.msg_text_2 = (TextView) view.findViewById(R.id.msg_text_2);
this.msg_timestamp_2 = (TextView) view.findViewById(R.id.timestamp_vertical);
}

@SuppressLint({"SimpleDateFormat", "UseCompatLoadingForDrawables"})
void bind(final int position) {
final Message item = getItem(position);
if(item.type < 2) {
msg_text.setText(item.text);
if(item.text.length() < 20) {
vertical_layout.setVisibility(View.GONE);
horizontal_layout.setVisibility(View.VISIBLE);
msg_text.setText(item.text);
} else {
vertical_layout.setVisibility(View.VISIBLE);
horizontal_layout.setVisibility(View.GONE);
msg_text_2.setText(item.text);
}
msg_timestamp.setText(item.timestamp);
if(item.type == 1) {
if(item.isError) {
Expand All @@ -89,6 +114,24 @@ void bind(final int position) {
.centerCrop()
.into((ImageView) convertView.findViewById(R.id.companion_avatar));
}
CardView cardView;
boolean isDarkTheme = PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("dark_theme", false);
if(item.type == 0) {
cardView = ((CardView) convertView.findViewById(R.id.incoming_msg_layout));
if (Global.checkMonet(ctx)) {
MonetCompat monet = MonetCompat.getInstance();
cardView.setCardBackgroundColor(
Objects.requireNonNull(monet.getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8());
} else {
if (isDarkTheme) {
cardView.setCardBackgroundColor(
MaterialColors.getColor(convertView, androidx.appcompat.R.attr.colorPrimaryDark));
} else {
cardView.setCardBackgroundColor(
MaterialColors.getColor(convertView, androidx.appcompat.R.attr.colorAccent));
}
}
}
} else {
msg_text.setText(item.text);
}
Expand Down
44 changes: 39 additions & 5 deletions app/src/main/res/layout-night/incoming_msg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:id="@+id/text_layout_horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingRight="8dp"
android:paddingBottom="4dp">
android:paddingBottom="4dp"
android:visibility="gone">

<TextView
<uk.openvk.android.refresh.user_interface.layouts.TightTextView
android:id="@+id/msg_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="8dp"
android:maxWidth="160dp"
android:text="Incoming message text example"
android:textColor="@android:color/white"
tools:ignore="HardcodedText"
android:textSize="16sp"/>
android:textSize="16sp"
android:maxWidth="220dp"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/timestamp"
Expand All @@ -61,6 +63,38 @@
android:textSize="10sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/text_layout_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingRight="8dp"
android:paddingBottom="4dp">

<uk.openvk.android.refresh.user_interface.layouts.TightTextView
android:id="@+id/msg_text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxWidth="220dp"
android:text="Incoming message text example"
android:textColor="@android:color/white"
android:textSize="16sp"
tools:ignore="HardcodedText" />

<TextView
android:id="@+id/timestamp_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_weight="1"
android:text="7:20"
android:textColor="#8fffffff"
android:textSize="10sp" />
</LinearLayout>

</androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit ef2a4f9

Please sign in to comment.