mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Show edit button on ShowHabitFragment
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.isoron.uhabits;
|
package org.isoron.uhabits;
|
||||||
|
|
||||||
|
import org.isoron.helpers.ReplayableActivity;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -10,7 +11,7 @@ import android.os.Bundle;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
public class ShowHabitActivity extends Activity
|
public class ShowHabitActivity extends ReplayableActivity
|
||||||
{
|
{
|
||||||
|
|
||||||
public Habit habit;
|
public Habit habit;
|
||||||
@@ -33,18 +34,19 @@ public class ShowHabitActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
{
|
{
|
||||||
getMenuInflater().inflate(R.menu.show_habit_menu, menu);
|
getMenuInflater().inflate(R.menu.show_habit_activity_menu, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item)
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
{
|
{
|
||||||
int id = item.getItemId();
|
switch(item.getItemId())
|
||||||
if(id == R.id.action_settings)
|
{
|
||||||
{
|
case R.id.action_settings:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,19 @@ import android.graphics.Color;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.isoron.helpers.ColorHelper;
|
import org.isoron.helpers.ColorHelper;
|
||||||
|
import org.isoron.helpers.Command;
|
||||||
|
import org.isoron.helpers.DialogHelper;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.ReminderHelper;
|
||||||
import org.isoron.uhabits.ShowHabitActivity;
|
import org.isoron.uhabits.ShowHabitActivity;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
import org.isoron.uhabits.views.HabitHistoryView;
|
import org.isoron.uhabits.views.HabitHistoryView;
|
||||||
@@ -19,9 +25,10 @@ import org.isoron.uhabits.views.HabitScoreView;
|
|||||||
import org.isoron.uhabits.views.HabitStreakView;
|
import org.isoron.uhabits.views.HabitStreakView;
|
||||||
import org.isoron.uhabits.views.RingView;
|
import org.isoron.uhabits.views.RingView;
|
||||||
|
|
||||||
public class ShowHabitFragment extends Fragment
|
public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedListener
|
||||||
{
|
{
|
||||||
protected ShowHabitActivity activity;
|
protected ShowHabitActivity activity;
|
||||||
|
private Habit habit;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart()
|
public void onStart()
|
||||||
@@ -37,7 +44,7 @@ public class ShowHabitFragment extends Fragment
|
|||||||
|
|
||||||
View view = inflater.inflate(R.layout.show_habit, container, false);
|
View view = inflater.inflate(R.layout.show_habit, container, false);
|
||||||
activity = (ShowHabitActivity) getActivity();
|
activity = (ShowHabitActivity) getActivity();
|
||||||
Habit habit = activity.habit;
|
habit = activity.habit;
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 21)
|
if (android.os.Build.VERSION.SDK_INT >= 21)
|
||||||
{
|
{
|
||||||
@@ -55,8 +62,8 @@ public class ShowHabitFragment extends Fragment
|
|||||||
tvStreaks.setTextColor(habit.color);
|
tvStreaks.setTextColor(habit.color);
|
||||||
|
|
||||||
LinearLayout llOverview = (LinearLayout) view.findViewById(R.id.llOverview);
|
LinearLayout llOverview = (LinearLayout) view.findViewById(R.id.llOverview);
|
||||||
llOverview.addView(new RingView(activity,
|
llOverview.addView(new RingView(activity, (int) activity.getResources().getDimension(
|
||||||
(int) activity.getResources().getDimension(R.dimen.small_square_size) * 4, habit.color,
|
R.dimen.small_square_size) * 4, habit.color,
|
||||||
((float) habit.getScore() / Habit.MAX_SCORE), "Habit strength"));
|
((float) habit.getScore() / Habit.MAX_SCORE), "Habit strength"));
|
||||||
|
|
||||||
LinearLayout llStrength = (LinearLayout) view.findViewById(R.id.llStrength);
|
LinearLayout llStrength = (LinearLayout) view.findViewById(R.id.llStrength);
|
||||||
@@ -73,6 +80,38 @@ public class ShowHabitFragment extends Fragment
|
|||||||
(int) activity.getResources().getDimension(R.dimen.small_square_size));
|
(int) activity.getResources().getDimension(R.dimen.small_square_size));
|
||||||
llStreaks.addView(hsv);
|
llStreaks.addView(hsv);
|
||||||
|
|
||||||
|
setHasOptionsMenu(true);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||||
|
{
|
||||||
|
inflater.inflate(R.menu.show_habit_fragment_menu, menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item)
|
||||||
|
{
|
||||||
|
switch (item.getItemId())
|
||||||
|
{
|
||||||
|
case R.id.action_edit_habit:
|
||||||
|
{
|
||||||
|
EditHabitFragment frag = EditHabitFragment.editSingleHabitFragment(habit.getId());
|
||||||
|
frag.setOnSavedListener(this);
|
||||||
|
frag.show(getFragmentManager(), "dialog");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaved(Command command)
|
||||||
|
{
|
||||||
|
activity.executeCommand(command);
|
||||||
|
ReminderHelper.createReminderAlarms(activity);
|
||||||
|
activity.recreate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
app/src/main/res/drawable-hdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 715 B |
BIN
app/src/main/res/drawable-mdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 471 B |
BIN
app/src/main/res/drawable-xhdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 916 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_action_edit.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_action_edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
10
app/src/main/res/menu/show_habit_fragment_menu.xml
Normal file
10
app/src/main/res/menu/show_habit_fragment_menu.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_edit_habit"
|
||||||
|
android:showAsAction="ifRoom"
|
||||||
|
android:icon="@drawable/ic_action_edit"
|
||||||
|
android:title="@string/edit"/>
|
||||||
|
|
||||||
|
</menu>
|
||||||
Reference in New Issue
Block a user