Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added double counter, Requesting help #58

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ repositories {
dependencies {
compile "com.android.support:support-v4:26.1.0"
compile "com.android.support:appcompat-v7:26.1.0"
compile 'com.android.support.constraint:constraint-layout:1.1.3'
}

android {
Expand Down
106 changes: 53 additions & 53 deletions src/main/java/me/tsukanov/counter/CounterApplication.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
package me.tsukanov.counter;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import java.util.SortedMap;
import java.util.Map;
import java.util.TreeMap;

import me.tsukanov.counter.ui.CounterFragment;

public class CounterApplication extends Application {

private static final String DATA_FILE_NAME = "counters";
public SortedMap<String, Integer> counters;
private SharedPreferences data;

@Override
public void onCreate() {
super.onCreate();
counters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

data = getBaseContext().getSharedPreferences(DATA_FILE_NAME, Context.MODE_PRIVATE);
loadCounters();
}

public void loadCounters() {
Map<String, ?> dataMap = data.getAll();
if (dataMap.isEmpty()) {
counters.put((String) getResources().getText(R.string.default_counter_name), CounterFragment.DEFAULT_VALUE);
} else {
for (Map.Entry<String, ?> entry : dataMap.entrySet()) {
counters.put(entry.getKey(), (Integer) entry.getValue());
}
}
}

public void saveCounters() {
SharedPreferences.Editor dataEditor = data.edit();
dataEditor.clear();
for (String name : counters.keySet()) {
dataEditor.putInt(name, counters.get(name));
}
dataEditor.commit();
}

public void removeCounters() {
counters.clear();
counters.put((String) getResources().getText(R.string.default_counter_name), CounterFragment.DEFAULT_VALUE);
}

}
package me.tsukanov.counter;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import java.util.SortedMap;
import java.util.Map;
import java.util.TreeMap;
import me.tsukanov.counter.ui.CounterFragment;
public class CounterApplication extends Application {
private static final String DATA_FILE_NAME = "counters";
public SortedMap<String, Integer> counters;
private SharedPreferences data;
@Override
public void onCreate() {
super.onCreate();
counters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
data = getBaseContext().getSharedPreferences(DATA_FILE_NAME, Context.MODE_PRIVATE);
loadCounters();
}
public void loadCounters() {
Map<String, ?> dataMap = data.getAll();
if (dataMap.isEmpty()) {
counters.put((String) getResources().getText(R.string.default_counter_name), CounterFragment.DEFAULT_VALUE);
} else {
for (Map.Entry<String, ?> entry : dataMap.entrySet()) {
counters.put(entry.getKey(), (Integer) entry.getValue());
}
}
}
public void saveCounters() {
SharedPreferences.Editor dataEditor = data.edit();
dataEditor.clear();
for (String name : counters.keySet()) {
dataEditor.putInt(name, counters.get(name));
}
dataEditor.commit();
}
public void removeCounters() {
counters.clear();
counters.put((String) getResources().getText(R.string.default_counter_name), CounterFragment.DEFAULT_VALUE);
}
}
Loading