import com.fasterxml.jackson.databind.ObjectWriter;
import net.ktnx.mobileledger.json.ParsedLedgerTransaction;
-import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerTransaction;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Globals;
import net.ktnx.mobileledger.utils.NetworkUtil;
import net.ktnx.mobileledger.utils.UrlEncodedFormData;
private String token;
private String session;
private LedgerTransaction ltr;
+ private MobileLedgerProfile mProfile;
- public SendTransactionTask(TaskCallback callback) {
+ public SendTransactionTask(TaskCallback callback, MobileLedgerProfile profile) {
taskCallback = callback;
+ mProfile = profile;
}
private boolean sendOK() throws IOException {
- HttpURLConnection http = NetworkUtil.prepareConnection(Data.profile.get(), "add");
+ HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
http.setRequestMethod("PUT");
http.setRequestProperty("Content-Type", "application/json");
http.setRequestProperty("Accept", "*/*");
return true;
}
private boolean legacySendOK() throws IOException {
- HttpURLConnection http = NetworkUtil.prepareConnection(Data.profile.get(), "add");
+ HttpURLConnection http = NetworkUtil.prepareConnection(mProfile, "add");
http.setRequestMethod("POST");
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
http.setRequestProperty("Accept", "*/*");
import android.content.Intent;
import android.content.pm.PackageInfo;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutManager;
import android.content.res.ColorStateList;
+import android.content.res.Resources;
import android.graphics.Color;
+import android.graphics.drawable.Icon;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import java.lang.ref.WeakReference;
import java.text.DateFormat;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Observer;
});
setupProfile();
+ onProfileChanged(null);
updateLastUpdateTextFromDB();
Date lastUpdate = Data.lastUpdateDate.get();
scheduleTransactionListRetrieval();
}
}
+ private void createShortcuts() {
+ Resources rm = getResources();
+ List<ShortcutInfo> shortcuts = new ArrayList<>();
+ try (LockHolder lh = Data.profiles.lockForReading()) {
+ for (int i = 0; i < Data.profiles.size(); i++) {
+ MobileLedgerProfile p = Data.profiles.get(i);
+ if (!p.isPostingPermitted()) continue;
+
+ ShortcutInfo si = new ShortcutInfo.Builder(this, "new_transaction_" + p.getUuid())
+ .setShortLabel(p.getName())
+ .setIcon(Icon.createWithResource(this, R.drawable.svg_thick_plus_white))
+ .setIntent(new Intent(Intent.ACTION_VIEW, null, this,
+ NewTransactionActivity.class).putExtra("profile_uuid", p.getUuid()))
+ .setRank(i)
+ .build();
+ shortcuts.add(si);
+ }
+ }
+ ShortcutManager sm = getSystemService(ShortcutManager.class);
+ sm.setDynamicShortcuts(shortcuts);
+ }
private void onProfileListChanged(Object arg) {
findViewById(R.id.nav_profile_list).setMinimumHeight(
(int) (getResources().getDimension(R.dimen.thumb_row_height) *
Log.d("profiles", "profile list changed");
if (arg == null) mProfileListAdapter.notifyDataSetChanged();
else mProfileListAdapter.notifyItemChanged((int) arg);
+
+ createShortcuts();
}
private void onProfileChanged(Object arg) {
MobileLedgerProfile profile = Data.profile.get();
}
public void onAccountSummaryRowViewClicked(View view) {
ViewGroup row;
- if ( view.getId() == R.id.account_expander ) row = (ViewGroup) view.getParent().getParent();
+ if (view.getId() == R.id.account_expander) row = (ViewGroup) view.getParent().getParent();
else row = (ViewGroup) view.getParent();
LedgerAccount acc = (LedgerAccount) row.getTag();
setContentView(R.layout.activity_new_transaction);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
- toolbar.setSubtitle(Data.profile.get().getName());
+ toolbar.setSubtitle(mProfile.getName());
tvDate = findViewById(R.id.new_transaction_date);
tvDate.setOnFocusChangeListener((v, hasFocus) -> {
// Log.d("swipe", "hooked to row "+i);
}
}
+ @Override
+ protected void initProfile() {
+ String profileUUID = getIntent().getStringExtra("profile_uuid");
+ if (profileUUID != null) {
+ mProfile = Data.getProfile(profileUUID);
+ if (mProfile == null) finish();
+ }
+ else super.initProfile();
+ }
@Override
public void finish() {
super.finish();
progress.setVisibility(View.VISIBLE);
try {
- saver = new SendTransactionTask(this);
+ saver = new SendTransactionTask(this, mProfile);
String dateString = tvDate.getText().toString();
Date date;
tr.addAccount(item);
}
- if (emptyAmountAccount != null) emptyAmountAccount.setAmount(-emptyAmountAccountBalance);
+ if (emptyAmountAccount != null)
+ emptyAmountAccount.setAmount(-emptyAmountAccountBalance);
saver.execute(tr);
}
catch (ParseException e) {
import android.annotation.SuppressLint;
import android.os.Bundle;
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Colors;
import androidx.annotation.Nullable;
@SuppressLint("Registered")
public class ProfileThemedActivity extends CrashReportingActivity {
+ protected MobileLedgerProfile mProfile;
protected void setupProfileColors() {
- Colors.setupTheme(this);
+ Colors.setupTheme(this, mProfile);
}
@Override
protected void onStart() {
Colors.refreshColors(getTheme());
}
protected void onCreate(@Nullable Bundle savedInstanceState) {
+ initProfile();
super.onCreate(savedInstanceState);
- Colors.setupTheme(this);
+ setupProfileColors();
+ }
+ protected void initProfile() {
+ mProfile = Data.profile.get();
}
}