Skip to content

Commit d3b9eda

Browse files
author
Sourav Das
committed
Changed UI
1 parent b76f7fb commit d3b9eda

File tree

15 files changed

+1030
-48
lines changed

15 files changed

+1030
-48
lines changed

app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ android {
2626
dependencies {
2727
implementation fileTree(dir: 'libs', include: ['*.jar'])
2828

29-
implementation 'androidx.appcompat:appcompat:1.0.2'
29+
implementation 'androidx.appcompat:appcompat:1.1.0'
3030
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3131
testImplementation 'junit:junit:4.12'
3232
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3333
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
34+
implementation 'androidx.core:core:1.3.0'
35+
implementation 'com.google.android.material:material:1.1.0'
3436
//Recycler View
3537
implementation "androidx.recyclerview:recyclerview:1.1.0"
3638
implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01"

app/src/main/java/com/sourav/story/MainActivity.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.sourav.story;
22

3-
import androidx.annotation.NonNull;
3+
import android.os.Bundle;
4+
import android.view.Menu;
5+
import android.view.MenuItem;
6+
import android.widget.Toast;
7+
48
import androidx.appcompat.app.AppCompatActivity;
9+
import androidx.appcompat.widget.Toolbar;
10+
import androidx.core.graphics.BlendModeColorFilterCompat;
11+
import androidx.core.graphics.BlendModeCompat;
512
import androidx.recyclerview.widget.LinearLayoutManager;
613
import androidx.recyclerview.widget.RecyclerView;
714

8-
import android.os.Bundle;
9-
import android.view.MotionEvent;
10-
import android.widget.Toast;
11-
1215
import java.util.ArrayList;
1316
import java.util.List;
1417

@@ -19,14 +22,29 @@ public class MainActivity extends AppCompatActivity implements OnRVClickListner{
1922
protected void onCreate(Bundle savedInstanceState) {
2023
super.onCreate(savedInstanceState);
2124
setContentView(R.layout.activity_main);
25+
initToolbar();
2226
getData();
2327
}
2428

29+
private void initToolbar() {
30+
Toolbar toolbar = findViewById(R.id.toolbar);
31+
toolbar.setNavigationIcon(R.drawable.ic_menu);
32+
toolbar.getNavigationIcon().setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
33+
getResources().getColor(R.color.grey_80),
34+
BlendModeCompat.SRC_ATOP));
35+
toolbar.setTitleTextColor(getResources().getColor(R.color.grey_80));
36+
setSupportActionBar(toolbar);
37+
getSupportActionBar().setTitle("News Light Horizontal");
38+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
39+
Tools.setSystemBarColor(this, R.color.grey_5);
40+
Tools.setSystemBarLight(this);
41+
}
42+
2543
private void getData() {
26-
story.add(new StoryData("1", "1","1"));
27-
story.add(new StoryData("2","2","2"));
28-
story.add(new StoryData("3","3","3"));
29-
story.add(new StoryData("4","4","4"));
44+
story.add(new StoryData("10:20 PM", "20 January","This is a demo text"));
45+
story.add(new StoryData("6:30 AM","5 February","This is something i've written"));
46+
story.add(new StoryData("9:30 PM","3 July","Good Night!"));
47+
story.add(new StoryData("7:25 PM","8 March","IDK what happened today"));
3048
initRview();
3149
}
3250

@@ -35,9 +53,25 @@ private void initRview() {
3553
NewAdapter newAdapter = new NewAdapter(this, story);
3654
recyclerView.setAdapter(newAdapter);
3755
recyclerView.setLayoutManager(new LinearLayoutManager(this));
38-
recyclerView.setItemViewCacheSize(0);
56+
recyclerView.setHasFixedSize(true);
3957
newAdapter.setOnClick(MainActivity.this);
58+
}
59+
60+
@Override
61+
public boolean onCreateOptionsMenu(Menu menu) {
62+
getMenuInflater().inflate(R.menu.menu_search_setting, menu);
63+
Tools.changeMenuIconColor(menu, getResources().getColor(R.color.grey_80));
64+
return true;
65+
}
4066

67+
@Override
68+
public boolean onOptionsItemSelected(MenuItem item) {
69+
if (item.getItemId() == android.R.id.home) {
70+
finish();
71+
} else {
72+
Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
73+
}
74+
return super.onOptionsItemSelected(item);
4175
}
4276

4377
@Override

app/src/main/java/com/sourav/story/NewAdapter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import android.view.LayoutInflater;
66
import android.view.View;
77
import android.view.ViewGroup;
8-
import android.widget.FrameLayout;
9-
import android.widget.RelativeLayout;
8+
import android.widget.LinearLayout;
109
import android.widget.TextView;
1110

1211
import androidx.annotation.NonNull;
@@ -58,7 +57,7 @@ class ViewHolder extends RecyclerView.ViewHolder {
5857
TextView title;
5958
TextView time;
6059
TextView date;
61-
RelativeLayout parent;
60+
LinearLayout parent;
6261
ViewHolder(@NonNull View itemView) {
6362
super(itemView);
6463
title = itemView.findViewById(R.id.listBody);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.sourav.story;
2+
3+
import android.app.Activity;
4+
import android.graphics.drawable.Drawable;
5+
import android.os.Build;
6+
import android.view.Menu;
7+
import android.view.View;
8+
import android.view.Window;
9+
import android.view.WindowManager;
10+
11+
import androidx.annotation.ColorInt;
12+
import androidx.annotation.ColorRes;
13+
import androidx.core.graphics.BlendModeColorFilterCompat;
14+
import androidx.core.graphics.BlendModeCompat;
15+
16+
public class Tools {
17+
18+
public static void setSystemBarColor(Activity act, @ColorRes int color) {
19+
Window window = act.getWindow();
20+
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
21+
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
22+
window.setStatusBarColor(act.getResources().getColor(color));
23+
}
24+
25+
public static void setSystemBarLight(Activity act) {
26+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
27+
View view = act.findViewById(android.R.id.content);
28+
int flags = view.getSystemUiVisibility();
29+
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
30+
view.setSystemUiVisibility(flags);
31+
}
32+
}
33+
34+
public static void changeMenuIconColor(Menu menu, @ColorInt int color) {
35+
for (int i = 0; i < menu.size(); i++) {
36+
Drawable drawable = menu.getItem(i).getIcon();
37+
if (drawable == null) continue;
38+
drawable.mutate();
39+
drawable.setColorFilter(BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
40+
color, BlendModeCompat.SRC_ATOP));;
41+
}
42+
}
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FFFFFFFF"
8+
android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
9+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="#FFFFFFFF"
8+
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
9+
</vector>
Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/parent_view"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7-
tools:context=".MainActivity">
7+
android:background="@android:color/white"
8+
android:orientation="vertical">
9+
10+
<com.google.android.material.appbar.AppBarLayout
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:theme="@style/AppTheme.AppBarOverlay"
14+
app:elevation="0dp">
15+
16+
<androidx.appcompat.widget.Toolbar
17+
android:id="@+id/toolbar"
18+
android:layout_width="match_parent"
19+
android:layout_height="?attr/actionBarSize"
20+
android:background="@android:color/white"
21+
app:contentInsetStartWithNavigation="0dp"
22+
app:layout_scrollFlags="scroll|enterAlways"
23+
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
24+
app:theme="@style/Toolbar.Light" />
25+
26+
</com.google.android.material.appbar.AppBarLayout>
827

928
<androidx.recyclerview.widget.RecyclerView
1029
android:id="@+id/recyclerView"
1130
android:layout_width="match_parent"
1231
android:layout_height="match_parent"
13-
android:padding="16dp"/>
14-
</RelativeLayout>
32+
android:scrollbars="vertical"
33+
android:scrollingCache="true"
34+
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
35+
36+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,55 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:id="@+id/parentLayout"
55
android:layout_width="match_parent"
6-
android:layout_height="wrap_content">
6+
android:layout_height="wrap_content"
7+
android:paddingStart="8dp"
8+
android:paddingEnd="8dp"
9+
android:paddingBottom="2dp">
710

8-
<TextView
9-
android:id="@+id/listDate"
10-
android:layout_width="wrap_content"
11-
android:layout_height="wrap_content"
12-
android:textStyle="bold"
13-
android:textSize="16sp"
14-
android:text="01 Jan 2001"/>
15-
16-
<TextView
17-
android:id="@+id/listBody"
11+
<androidx.cardview.widget.CardView
1812
android:layout_width="match_parent"
1913
android:layout_height="wrap_content"
20-
android:text="Bla bla bla bla bla bla bla"
21-
android:textSize="20sp"
22-
android:layout_below="@+id/listDate"/>
14+
android:foreground="?android:attr/selectableItemBackground"
15+
app:cardCornerRadius="8dp"
16+
app:cardElevation="2dp"
17+
app:cardPreventCornerOverlap="true"
18+
app:cardUseCompatPadding="true">
19+
<RelativeLayout
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:paddingStart="8dp"
23+
android:paddingTop="4dp"
24+
android:paddingEnd="8dp"
25+
android:paddingBottom="4dp">
26+
<TextView
27+
android:id="@+id/listDate"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:text="01 Jan 2001"
31+
android:textSize="18sp"
32+
android:textStyle="bold"/>
2333

24-
<TextView
25-
android:id="@+id/listTime"
26-
android:layout_width="wrap_content"
27-
android:layout_height="wrap_content"
28-
android:text="10:10 PM"
29-
android:layout_below="@+id/listBody"
30-
android:layout_alignParentEnd="true"/>
31-
</RelativeLayout>
34+
<TextView
35+
android:id="@+id/listBody"
36+
android:layout_width="match_parent"
37+
android:layout_height="wrap_content"
38+
android:layout_below="@+id/listDate"
39+
android:layout_marginTop="4dp"
40+
android:fontFamily="sans-serif"
41+
android:text="Bla bla bla bla bla bla bla"
42+
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
43+
android:textSize="20sp"/>
44+
45+
<TextView
46+
android:id="@+id/listTime"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:layout_below="@+id/listBody"
50+
android:layout_alignParentEnd="true"
51+
android:text="10:10 PM"/>
52+
</RelativeLayout>
53+
</androidx.cardview.widget.CardView>
54+
55+
</LinearLayout>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto">
3+
4+
<item
5+
android:id="@+id/action_search"
6+
android:icon="@drawable/ic_search"
7+
android:orderInCategory="100"
8+
android:title="Search"
9+
app:showAsAction="always" />
10+
11+
<item
12+
android:id="@+id/action_settings"
13+
android:orderInCategory="100"
14+
android:title="Settings"
15+
app:showAsAction="never" />
16+
</menu>

0 commit comments

Comments
 (0)