Skip to content

Commit

Permalink
Redesigned home and counter page
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Saifullah Khan committed Oct 24, 2017
1 parent 7c30186 commit 592dab6
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 228 deletions.
13 changes: 7 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "pk.aspirasoft.tasbih"
minSdkVersion 14
targetSdkVersion 25
versionCode 3
versionName "1.2"
targetSdkVersion 26
versionCode 4
versionName "2.0"
}
buildTypes {
release {
Expand All @@ -21,8 +21,9 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.google.firebase:firebase-ads:10.0.1'
compile 'com.github.lzyzsd:circleprogress:1.2.1'
testCompile 'junit:junit:4.12'
}

Expand Down
21 changes: 19 additions & 2 deletions app/src/main/java/pk/aspirasoft/tasbih/data/Counter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ public class Counter {
private final String name;
private final String description;
private int value;
private int max;

public Counter(String rawData) throws IndexOutOfBoundsException {
String[] data = rawData.split(sep);
this.name = data[0];
this.description = data[1];
this.value = Integer.parseInt(data[2]);

try {
this.max = Integer.parseInt(data[3]);
} catch (IndexOutOfBoundsException ex) {
this.max = 100;
}
}

public Counter(String name, String description) {
this.name = name;
this.description = description;
this.value = 0;
this.max = 100;
}

public String getName() {
Expand All @@ -41,7 +49,7 @@ public void setValue(int value) throws ArithmeticException {
}

public void increment() {
this.value ++;
this.value++;
}

public void decrement() {
Expand All @@ -57,7 +65,16 @@ public String toString() {
String string = "";
string += name + sep;
string += description + sep;
string += String.valueOf(value);
string += String.valueOf(value) + sep;
string += String.valueOf(max);
return string;
}

public int getMax() {
return max;
}

public void setMax(int max) {
this.max = max;
}
}
32 changes: 22 additions & 10 deletions app/src/main/java/pk/aspirasoft/tasbih/scenes/ActiveCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import pk.aspirasoft.tasbih.R;
import pk.aspirasoft.tasbih.data.Counter;
import pk.aspirasoft.tasbih.data.CounterManager;
import pk.aspirasoft.tasbih.views.CounterView;

public class ActiveCounter extends AppCompatActivity implements View.OnClickListener {
public class ActiveCounter extends AppCompatActivity implements View.OnClickListener, View.OnLongClickListener {

private Counter counter;
private CounterView counterView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -43,6 +45,10 @@ public void onAdLoaded() {
mAdView.loadAd(adRequest);

counter = new Counter(getIntent().getStringExtra("counter"));
counterView = (CounterView) findViewById(R.id.counter);
counterView.setOnLongClickListener(this);
counterView.setOnClickListener(this);
counterView.setMax(counter.getMax());

setSupportActionBar((Toolbar) findViewById(R.id.actionBar));
ActionBar actionBar = getSupportActionBar();
Expand All @@ -51,12 +57,8 @@ public void onAdLoaded() {
actionBar.setDisplayHomeAsUpEnabled(true);
}

if (!counter.getDescription().equals(""))
((TextView) findViewById(R.id.description)).setText(counter.getDescription());
((TextView) findViewById(R.id.description)).setText(counter.getDescription());
updateUI();

findViewById(R.id.plus).setOnClickListener(this);
findViewById(R.id.minus).setOnClickListener(this);
}

@Override
Expand Down Expand Up @@ -133,21 +135,30 @@ public void onClick(DialogInterface dialog, int which) {
}

private void updateUI() {
((TextView) findViewById(R.id.value)).setText(String.valueOf(counter.getValue()));
counterView.setCompleted(counter.getValue() / counter.getMax());
counterView.setProgress(counter.getValue() % counter.getMax());
}

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.plus:
case R.id.counter:
counter.increment();
updateUI();
break;
case R.id.minus:
}
}


@Override
public boolean onLongClick(View view) {
switch (view.getId()) {
case R.id.counter:
counter.decrement();
updateUI();
break;
return true;
}
return false;
}

@Override
Expand All @@ -162,4 +173,5 @@ public void onPause() {
manager.diskOut();
super.onPause();
}

}
47 changes: 7 additions & 40 deletions app/src/main/java/pk/aspirasoft/tasbih/scenes/CounterDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
Expand All @@ -27,7 +26,7 @@

public class CounterDrawer extends AppCompatActivity implements View.OnClickListener {

private boolean gridView = true;
private boolean gridView = false;
private CounterManager manager;
private LinearLayout rootView;

Expand Down Expand Up @@ -212,37 +211,17 @@ private void showList() {
rootView = (LinearLayout) findViewById(R.id.rootView);
rootView.removeAllViews();

// Inflate new counter button
getLayoutInflater().inflate(R.layout.drawer_list_item, rootView);

LinearLayout cell = (LinearLayout) rootView.getChildAt(rootView.getChildCount() - 1);
ImageButton logo = (ImageButton) cell.findViewById(R.id.logo);
TextView label = (TextView) cell.findViewById(R.id.title);
TextView about = (TextView) cell.findViewById(R.id.description);

logo.setImageResource(android.R.drawable.ic_menu_add);
label.setText(getString(R.string.label_add));
about.setText(getString(R.string.label_add_description));

cell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getApplicationContext(), CreateCounter.class));
}
});

for (int i = 0; i < manager.size(); i++) {
// Inflate cell
getLayoutInflater().inflate(R.layout.drawer_list_item, rootView);

cell = (LinearLayout) rootView.getChildAt(rootView.getChildCount() - 1);
logo = (ImageButton) cell.findViewById(R.id.logo);
label = (TextView) cell.findViewById(R.id.title);
about = (TextView) cell.findViewById(R.id.description);
LinearLayout cell = (LinearLayout) rootView.getChildAt(rootView.getChildCount() - 1);
TextView label = (TextView) cell.findViewById(R.id.title);
TextView value = (TextView) cell.findViewById(R.id.value);

final Counter counter = manager.get(i);
label.setText(counter.getName());
about.setText(counter.getDescription());
value.setText(String.valueOf(counter.getValue()));

cell.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -267,26 +246,14 @@ private void updateDisplay() {
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.home, menu);
MenuItem item = menu.getItem(0);

// Read view preferences
gridView = getSharedPreferences("count-drawer", MODE_PRIVATE)
.getBoolean("GridView", true);

// Change action bar icon
if (gridView) {
item.setIcon(R.drawable.ic_action_list);
} else {
item.setIcon(R.drawable.ic_action_grid);
}
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.toggleView:
toggleView(item);
case R.id.add_counter:
startActivity(new Intent(getApplicationContext(), CreateCounter.class));
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down
78 changes: 78 additions & 0 deletions app/src/main/java/pk/aspirasoft/tasbih/views/CounterView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package pk.aspirasoft.tasbih.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.github.lzyzsd.circleprogress.CircleProgress;
import com.github.lzyzsd.circleprogress.DonutProgress;

import pk.aspirasoft.tasbih.R;


public class CounterView extends RelativeLayout {

private int progress = 0;
private int max = 100;

private DonutProgress donutProgress;
private CircleProgress circleProgress;

public CounterView(Context context) {
super(context);
init();
}

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

public CounterView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

private void init() {
View.inflate(getContext(), R.layout.counter, this);

donutProgress = findViewById(R.id.donut_progress);
donutProgress.setProgress(progress);
donutProgress.setMax(max);

circleProgress = findViewById(R.id.circle_progress);
circleProgress.setProgress(progress);
circleProgress.setMax(max);
}

public int getProgress() {
return progress;
}

public void setProgress(int progress) {
this.progress = progress;

donutProgress.setProgress(progress);
circleProgress.setProgress(progress);
}

public int getMax() {
return max;
}

public void setMax(int max) {
this.max = max;

donutProgress.setMax(max);
circleProgress.setMax(max);
}

public void setCompleted(int completed) {
String text = getResources().getString(R.string.label_finished, completed);

TextView finished = findViewById(R.id.finished);
finished.setText(text);
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/list_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="100dp" />
<solid android:color="@color/colorAccent" />
</shape>
41 changes: 41 additions & 0 deletions app/src/main/res/layout/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.github.lzyzsd.circleprogress.DonutProgress
android:id="@+id/donut_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="4dp"
custom:donut_finished_color="#000"
custom:donut_finished_stroke_width="10dp"
custom:donut_max="33"
custom:donut_progress="15"
custom:donut_text=""
custom:donut_unfinished_color="@android:color/darker_gray"
custom:donut_unfinished_stroke_width="10dp" />

<com.github.lzyzsd.circleprogress.CircleProgress
android:id="@+id/circle_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
custom:circle_finished_color="@color/colorAccent"
custom:circle_max="33"
custom:circle_progress="15"
custom:circle_suffix_text=""
custom:circle_unfinished_color="#000" />

<TextView
android:id="@+id/finished"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="@string/label_finished"
android:textStyle="bold" />

</RelativeLayout>

Loading

0 comments on commit 592dab6

Please sign in to comment.