Replace AXT with KAXT or native kotlin code & cleanup
This commit is contained in:
parent
8bca0eb83a
commit
001326c40d
29 changed files with 345 additions and 560 deletions
|
@ -149,7 +149,7 @@ dependencies {
|
|||
|
||||
compile 'net.i2p.android.ext:floatingactionbutton:1.10.1'
|
||||
|
||||
compile 'org.ligi:AXT:0.37'
|
||||
compile 'com.github.ligi:KAXT:0.6'
|
||||
compile 'org.ligi:tracedroid:1.4'
|
||||
compile 'com.github.ligi:snackengage:0.9'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.4.2'
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.squareup.moshi.JsonDataException
|
|||
import com.squareup.moshi.Moshi
|
||||
import okio.Okio
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.BuildConfig
|
||||
import org.ligi.passandroid.events.PassStoreChangeEvent
|
||||
|
@ -99,7 +98,7 @@ class AndroidFileSystemPassStore(private val context: Context, settings: Setting
|
|||
}
|
||||
|
||||
override fun deletePassWithId(id: String): Boolean {
|
||||
val result = AXT.at(getPathForID(id)).deleteRecursive()
|
||||
val result = getPathForID(id).deleteRecursively()
|
||||
if (result) {
|
||||
passMap.remove(id)
|
||||
classifier.removePass(id)
|
||||
|
|
|
@ -3,14 +3,11 @@ package org.ligi.passandroid.model.pass
|
|||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import com.squareup.moshi.JsonQualifier
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.passandroid.model.PassStore
|
||||
import org.ligi.tracedroid.logging.Log
|
||||
import org.threeten.bp.ZonedDateTime
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
class PassImpl(override val id: String) : Pass {
|
||||
|
@ -74,17 +71,10 @@ class PassImpl(override val id: String) : Pass {
|
|||
}
|
||||
|
||||
override fun getSource(passStore: PassStore): String? {
|
||||
val file = File(passStore.getPathForID(id), "source.obj")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
return AXT.at(file).loadToObject()
|
||||
} catch (e: IOException) {
|
||||
// OK no source info - no big deal - but log
|
||||
Log.w("pass source info file exists but not readable" + e)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
Log.w("pass source info file exists but not readable" + e)
|
||||
}
|
||||
val file = File(passStore.getPathForID(id), "source.txt")
|
||||
|
||||
if (file.exists()) {
|
||||
return file.bufferedReader().readText()
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ package org.ligi.passandroid.reader
|
|||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.kaxt.parseColor
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.helper.CategoryHelper
|
||||
|
@ -62,7 +63,7 @@ object AppleStylePassReader {
|
|||
|
||||
for (charset in Charset.availableCharsets().values) {
|
||||
try {
|
||||
val json_str = AXT.at(file).readToString(charset)
|
||||
val json_str = file.bufferedReader(charset).readText()
|
||||
pass_json = SafeJSONReader.readJSONSafely(json_str)
|
||||
} catch (ignored: Exception) {
|
||||
// we try with next charset
|
||||
|
@ -154,7 +155,7 @@ object AppleStylePassReader {
|
|||
|
||||
readJsonSafe(pass_json, "backgroundColor", object : JsonStringReadCallback {
|
||||
override fun onString(string: String) {
|
||||
pass.accentColor = AXT.at(string).parseColor(0)
|
||||
pass.accentColor = string.parseColor(Color.BLACK)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.ligi.passandroid.reader
|
||||
|
||||
import android.graphics.Color
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.passandroid.helper.SafeJSONReader
|
||||
import org.ligi.passandroid.model.PassDefinitions
|
||||
import org.ligi.passandroid.model.pass.BarCode
|
||||
|
@ -21,7 +20,7 @@ object PassReader {
|
|||
val file = File(path, "data.json")
|
||||
|
||||
try {
|
||||
val plainJsonString = AXT.at(file).readToString()
|
||||
val plainJsonString = file.bufferedReader().readText()
|
||||
val pass_json = SafeJSONReader.readJSONSafely(plainJsonString)
|
||||
|
||||
if (pass_json.has("what")) {
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package org.ligi.passandroid.reader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.ligi.axt.AXT;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class TAMMultiPassReader {
|
||||
|
||||
public static final String START_TOKEN = "<td class=\"saveBlock\"><a href=\"";
|
||||
|
||||
final String content;
|
||||
|
||||
public TAMMultiPassReader(final String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public TAMMultiPassReader(final InputStream ins) throws IOException {
|
||||
this.content = AXT.at(ins).readToString();
|
||||
}
|
||||
|
||||
|
||||
public boolean isTAMMultiPass() {
|
||||
return content.contains("<title>TAM Online check-in</title>");
|
||||
}
|
||||
|
||||
/*
|
||||
if you try to parse the xml:
|
||||
org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 282; The string "--" is not permitted within comments.
|
||||
been there - done that .. broken xml :-(
|
||||
*/
|
||||
public List<String> getLinks() throws ParserConfigurationException, IOException, SAXException {
|
||||
|
||||
final List<String> result = new ArrayList<>();
|
||||
|
||||
int currentPosition = 0;
|
||||
while ((currentPosition = content.indexOf(START_TOKEN, currentPosition + 1)) != -1) {
|
||||
final String substring = content.substring(currentPosition + START_TOKEN.length(), content.indexOf("class=\"saveLink\"", currentPosition + 1));
|
||||
result.add(substring.substring(0, substring.lastIndexOf("\"")));
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ import android.view.ViewGroup
|
|||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.kaxt.getSmallestSide
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.model.pass.BarCode
|
||||
|
||||
|
@ -31,7 +31,7 @@ internal class BarcodeUIController(rootView: View, private val barCode: BarCode?
|
|||
}
|
||||
|
||||
if (barCode != null) {
|
||||
val smallestSide = AXT.at(activity.windowManager).smallestSide
|
||||
val smallestSide = activity.windowManager.getSmallestSide()
|
||||
|
||||
val bitmapDrawable = barCode.getBitmap(activity.resources)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import android.os.Bundle
|
|||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import kotlinx.android.synthetic.main.fullscreen_image.*
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.kaxt.lockOrientation
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.tracedroid.logging.Log
|
||||
|
||||
|
@ -56,7 +56,7 @@ class FullscreenBarcodeActivity : PassViewActivityBase() {
|
|||
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT,
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT -> return // do nothing
|
||||
|
||||
else -> AXT.at(this).lockOrientation(Configuration.ORIENTATION_PORTRAIT)
|
||||
else -> lockOrientation(Configuration.ORIENTATION_PORTRAIT)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -67,7 +67,7 @@ class FullscreenBarcodeActivity : PassViewActivityBase() {
|
|||
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE -> return // do nothing
|
||||
|
||||
else -> AXT.at(this).lockOrientation(Configuration.ORIENTATION_LANDSCAPE)
|
||||
else -> lockOrientation(Configuration.ORIENTATION_LANDSCAPE)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.ligi.passandroid.ui
|
|||
import android.app.ProgressDialog
|
||||
import android.net.Uri
|
||||
import android.os.AsyncTask
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.model.InputStreamWithSource
|
||||
import org.ligi.passandroid.ui.UnzipPassController.InputStreamUnzipControllerSpec
|
||||
|
@ -61,7 +61,7 @@ internal class ImportAndShowAsyncTask(val passImportActivity: PassImportActivity
|
|||
|
||||
passImportActivity.passStore.classifier.moveToTopic(passbookForId!!, passImportActivity.getString(R.string.topic_new))
|
||||
|
||||
AXT.at(passImportActivity).startCommonIntent().activityFromClass(PassViewActivity::class.java)
|
||||
passImportActivity.startActivityFromClass(PassViewActivity::class.java)
|
||||
passImportActivity.finish()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
package org.ligi.passandroid.ui;
|
||||
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.ligi.axt.AXT;
|
||||
import org.ligi.passandroid.App;
|
||||
import org.ligi.passandroid.R;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.model.PassStoreProjection;
|
||||
import org.ligi.passandroid.model.Settings;
|
||||
import org.ligi.passandroid.model.pass.Pass;
|
||||
import org.ligi.passandroid.ui.pass_view_holder.CondensedPassViewHolder;
|
||||
import org.ligi.passandroid.ui.pass_view_holder.PassViewHolder;
|
||||
import org.ligi.passandroid.ui.pass_view_holder.VerbosePassViewHolder;
|
||||
|
||||
public class PassAdapter extends RecyclerView.Adapter<PassViewHolder> {
|
||||
|
||||
@Inject
|
||||
PassStore passStore;
|
||||
|
||||
@Inject
|
||||
Settings settings;
|
||||
|
||||
protected final AppCompatActivity passListActivity;
|
||||
private final PassStoreProjection passStoreProjection;
|
||||
|
||||
public PassAdapter(AppCompatActivity passListActivity, PassStoreProjection passStoreProjection) {
|
||||
this.passStoreProjection = passStoreProjection;
|
||||
App.component().inject(this);
|
||||
this.passListActivity = passListActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PassViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
final LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
|
||||
|
||||
final CardView res = (CardView) inflater.inflate(R.layout.pass_list_item, viewGroup, false);
|
||||
if (settings.isCondensedModeEnabled()) {
|
||||
return new CondensedPassViewHolder(res);
|
||||
} else {
|
||||
return new VerbosePassViewHolder(res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final PassViewHolder viewHolder, int position) {
|
||||
final Pass pass = passStoreProjection.getPassList().get(position);
|
||||
|
||||
viewHolder.apply(pass, passStore, passListActivity);
|
||||
|
||||
final CardView root = viewHolder.getView();
|
||||
|
||||
root.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
passStore.setCurrentPass(pass);
|
||||
AXT.at(passListActivity).startCommonIntent().activityFromClass(PassViewActivity.class);
|
||||
}
|
||||
});
|
||||
|
||||
root.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
Snackbar.make(root, R.string.please_use_the_swipe_feature, Snackbar.LENGTH_LONG).show();
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
private List<Pass> getList() {
|
||||
return passStoreProjection.getPassList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return getList().size();
|
||||
}
|
||||
|
||||
}
|
74
android/src/main/java/org/ligi/passandroid/ui/PassAdapter.kt
Normal file
74
android/src/main/java/org/ligi/passandroid/ui/PassAdapter.kt
Normal file
|
@ -0,0 +1,74 @@
|
|||
package org.ligi.passandroid.ui
|
||||
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.CardView
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.model.PassStore
|
||||
import org.ligi.passandroid.model.PassStoreProjection
|
||||
import org.ligi.passandroid.model.Settings
|
||||
import org.ligi.passandroid.model.pass.Pass
|
||||
import org.ligi.passandroid.ui.pass_view_holder.CondensedPassViewHolder
|
||||
import org.ligi.passandroid.ui.pass_view_holder.PassViewHolder
|
||||
import org.ligi.passandroid.ui.pass_view_holder.VerbosePassViewHolder
|
||||
import javax.inject.Inject
|
||||
|
||||
class PassAdapter(private val passListActivity: AppCompatActivity, private val passStoreProjection: PassStoreProjection) : RecyclerView.Adapter<PassViewHolder>() {
|
||||
|
||||
@Inject
|
||||
lateinit var passStore: PassStore
|
||||
|
||||
@Inject
|
||||
lateinit var settings: Settings
|
||||
|
||||
init {
|
||||
App.component().inject(this)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): PassViewHolder {
|
||||
val inflater = LayoutInflater.from(viewGroup.context)
|
||||
|
||||
val res = inflater.inflate(R.layout.pass_list_item, viewGroup, false) as CardView
|
||||
if (settings.isCondensedModeEnabled) {
|
||||
return CondensedPassViewHolder(res)
|
||||
} else {
|
||||
return VerbosePassViewHolder(res)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: PassViewHolder, position: Int) {
|
||||
val pass = passStoreProjection.passList[position]
|
||||
|
||||
viewHolder.apply(pass, passStore, passListActivity)
|
||||
|
||||
val root = viewHolder.view
|
||||
|
||||
root.setOnClickListener {
|
||||
passStore.currentPass = pass
|
||||
passListActivity.startActivityFromClass(PassViewActivity::class.java)
|
||||
}
|
||||
|
||||
root.setOnLongClickListener {
|
||||
Snackbar.make(root, R.string.please_use_the_swipe_feature, Snackbar.LENGTH_LONG).show()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
return position.toLong()
|
||||
}
|
||||
|
||||
private val list: List<Pass>
|
||||
get() = passStoreProjection.passList
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
|
||||
}
|
|
@ -6,14 +6,13 @@ import android.os.Bundle
|
|||
import android.support.annotation.IdRes
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.text.Editable
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import kotlinx.android.synthetic.main.edit.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.ligi.axt.simplifications.SimpleTextWatcher
|
||||
import org.ligi.kaxt.doAfterEdit
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.events.PassRefreshEvent
|
||||
|
@ -63,12 +62,10 @@ class PassEditActivity : AppCompatActivity() {
|
|||
}
|
||||
}.show()
|
||||
}
|
||||
passTitle.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
super.afterTextChanged(s)
|
||||
currentPass.description = s!!.toString()
|
||||
}
|
||||
})
|
||||
passTitle.doAfterEdit {
|
||||
currentPass.description = it.toString()
|
||||
}
|
||||
|
||||
val currentPass = passStore.currentPass
|
||||
if (currentPass != null) {
|
||||
this.currentPass = currentPass as PassImpl
|
||||
|
|
|
@ -21,8 +21,9 @@ import android.widget.TextView
|
|||
import kotlinx.android.synthetic.main.pass_list.*
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.axt.listeners.ActivityFinishingOnClickListener
|
||||
import org.ligi.kaxt.setVisibility
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.kaxt.startActivityFromURL
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.events.PassStoreChangeEvent
|
||||
|
@ -95,7 +96,9 @@ class PassListActivity : PassAndroidActivity() {
|
|||
pd.setMessage(getString(R.string.scan_progressdialog_message))
|
||||
pd.setCancelable(false)
|
||||
pd.isIndeterminate = true
|
||||
pd.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.scan_dialog_send_background_button), ActivityFinishingOnClickListener(this))
|
||||
pd.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.scan_dialog_send_background_button), { dialogInterface: DialogInterface, i: Int ->
|
||||
this@PassListActivity.finish()
|
||||
})
|
||||
pd.show()
|
||||
}
|
||||
|
||||
|
@ -136,7 +139,7 @@ class PassListActivity : PassAndroidActivity() {
|
|||
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
AXT.at(fab_action_open_file).setVisibility(Build.VERSION.SDK_INT >= VERSION_STARTING_TO_SUPPORT_STORAGE_FRAMEWORK)
|
||||
fab_action_open_file.setVisibility(Build.VERSION.SDK_INT >= VERSION_STARTING_TO_SUPPORT_STORAGE_FRAMEWORK)
|
||||
|
||||
// don't want too many windows in worst case - so check for errors first
|
||||
if (TraceDroid.getStackTraceFiles().size > 0) {
|
||||
|
@ -194,7 +197,7 @@ class PassListActivity : PassAndroidActivity() {
|
|||
val pass = PassTemplates.createAndAddEmptyPass(passStore, resources)
|
||||
|
||||
fam.collapse()
|
||||
AXT.at(this).startCommonIntent().activityFromClass(PassEditActivity::class.java)
|
||||
startActivityFromClass(PassEditActivity::class.java)
|
||||
|
||||
val newTitle: String
|
||||
if (tab_layout.selectedTabPosition < 0) {
|
||||
|
@ -212,7 +215,7 @@ class PassListActivity : PassAndroidActivity() {
|
|||
}
|
||||
|
||||
fab_action_demo_pass.setOnClickListener {
|
||||
AXT.at(this).startCommonIntent().openUrl("http://espass.it/examples")
|
||||
startActivityFromURL("http://espass.it/examples")
|
||||
fam.collapse()
|
||||
}
|
||||
|
||||
|
@ -224,7 +227,7 @@ class PassListActivity : PassAndroidActivity() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
|
||||
R.id.menu_help -> {
|
||||
AXT.at(this).startCommonIntent().activityFromClass(HelpActivity::class.java)
|
||||
startActivityFromClass(HelpActivity::class.java)
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
package org.ligi.passandroid.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import java.io.File;
|
||||
import javax.inject.Inject;
|
||||
import org.ligi.axt.AXT;
|
||||
import org.ligi.passandroid.App;
|
||||
import org.ligi.passandroid.R;
|
||||
import org.ligi.passandroid.Tracker;
|
||||
import org.ligi.passandroid.maps.PassbookMapsFacade;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
import org.ligi.passandroid.model.Settings;
|
||||
import org.ligi.passandroid.model.pass.Pass;
|
||||
import org.ligi.passandroid.printing.PrintHelper;
|
||||
|
||||
public class PassMenuOptions {
|
||||
|
||||
@Inject
|
||||
PassStore passStore;
|
||||
|
||||
@Inject
|
||||
Tracker tracker;
|
||||
|
||||
@Inject
|
||||
Settings settings;
|
||||
|
||||
public final Activity activity;
|
||||
public final Pass pass;
|
||||
|
||||
public PassMenuOptions(final Activity activity, final Pass pass) {
|
||||
App.component().inject(this);
|
||||
this.activity = activity;
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
public boolean process(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case R.id.menu_delete:
|
||||
tracker.trackEvent("ui_action", "delete", "delete", null);
|
||||
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setMessage(activity.getString(R.string.dialog_delete_confirm_text));
|
||||
builder.setTitle(activity.getString(org.ligi.passandroid.R.string.dialog_delete_title));
|
||||
builder.setIcon(R.drawable.ic_alert_warning);
|
||||
|
||||
final View sourceDeleteCheckBoxView = LayoutInflater.from(activity).inflate(R.layout.delete_dialog_layout, null);
|
||||
final CheckBox sourceDeleteCheckBox = (CheckBox) sourceDeleteCheckBoxView.findViewById(R.id.sourceDeleteCheckbox);
|
||||
|
||||
final String source = pass.getSource(passStore);
|
||||
if (source != null && source.startsWith("file://")) {
|
||||
|
||||
sourceDeleteCheckBox.setText(activity.getString(R.string.dialog_delete_confirm_delete_source_checkbox));
|
||||
builder.setView(sourceDeleteCheckBoxView);
|
||||
}
|
||||
|
||||
builder.setPositiveButton(activity.getString(R.string.delete), new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (sourceDeleteCheckBox.isChecked()) {
|
||||
//noinspection ConstantConditions - we are sure source is not null - as only then sourceDeleteCheckBox
|
||||
new File(source.replace("file://", "")).delete();
|
||||
}
|
||||
passStore.deletePassWithId(pass.getId());
|
||||
if (activity instanceof PassViewActivityBase) {
|
||||
final Intent passListIntent = new Intent(activity, PassListActivity.class);
|
||||
NavUtils.navigateUpTo(activity, passListIntent);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.no, null);
|
||||
|
||||
builder.show();
|
||||
|
||||
return true;
|
||||
|
||||
case R.id.menu_map:
|
||||
PassbookMapsFacade.startFullscreenMap(activity);
|
||||
return true;
|
||||
|
||||
case R.id.menu_share:
|
||||
tracker.trackEvent("ui_action", "share", "shared", null);
|
||||
new PassExportTaskAndShare(activity, passStore.getPathForID(pass.getId())).execute();
|
||||
return true;
|
||||
|
||||
case R.id.menu_edit:
|
||||
tracker.trackEvent("ui_action", "share", "shared", null);
|
||||
passStore.setCurrentPass(pass);
|
||||
AXT.at(activity).startCommonIntent().activityFromClass(PassEditActivity.class);
|
||||
return true;
|
||||
|
||||
case R.id.menu_print:
|
||||
PrintHelper.doPrint(activity, pass);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
102
android/src/main/java/org/ligi/passandroid/ui/PassMenuOptions.kt
Normal file
102
android/src/main/java/org/ligi/passandroid/ui/PassMenuOptions.kt
Normal file
|
@ -0,0 +1,102 @@
|
|||
package org.ligi.passandroid.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.support.v4.app.NavUtils
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.widget.CheckBox
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.Tracker
|
||||
import org.ligi.passandroid.maps.PassbookMapsFacade
|
||||
import org.ligi.passandroid.model.PassStore
|
||||
import org.ligi.passandroid.model.Settings
|
||||
import org.ligi.passandroid.model.pass.Pass
|
||||
import org.ligi.passandroid.printing.PrintHelper
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
class PassMenuOptions(val activity: Activity, val pass: Pass) {
|
||||
|
||||
@Inject
|
||||
lateinit var passStore: PassStore
|
||||
|
||||
@Inject
|
||||
lateinit var tracker: Tracker
|
||||
|
||||
@Inject
|
||||
lateinit var settings: Settings
|
||||
|
||||
init {
|
||||
App.component().inject(this)
|
||||
}
|
||||
|
||||
fun process(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
|
||||
R.id.menu_delete -> {
|
||||
tracker.trackEvent("ui_action", "delete", "delete", null)
|
||||
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
builder.setMessage(activity.getString(R.string.dialog_delete_confirm_text))
|
||||
builder.setTitle(activity.getString(org.ligi.passandroid.R.string.dialog_delete_title))
|
||||
builder.setIcon(R.drawable.ic_alert_warning)
|
||||
|
||||
val sourceDeleteCheckBoxView = LayoutInflater.from(activity).inflate(R.layout.delete_dialog_layout, null)
|
||||
val sourceDeleteCheckBox = sourceDeleteCheckBoxView.findViewById(R.id.sourceDeleteCheckbox) as CheckBox
|
||||
|
||||
val source = pass.getSource(passStore)
|
||||
if (source != null && source.startsWith("file://")) {
|
||||
|
||||
sourceDeleteCheckBox.text = activity.getString(R.string.dialog_delete_confirm_delete_source_checkbox)
|
||||
builder.setView(sourceDeleteCheckBoxView)
|
||||
}
|
||||
|
||||
builder.setPositiveButton(activity.getString(R.string.delete)) { dialog, which ->
|
||||
if (sourceDeleteCheckBox.isChecked) {
|
||||
|
||||
File(source!!.replace("file://", "")).delete()
|
||||
}
|
||||
passStore.deletePassWithId(pass.id)
|
||||
if (activity is PassViewActivityBase) {
|
||||
val passListIntent = Intent(activity, PassListActivity::class.java)
|
||||
NavUtils.navigateUpTo(activity, passListIntent)
|
||||
}
|
||||
}
|
||||
builder.setNegativeButton(android.R.string.no, null)
|
||||
|
||||
builder.show()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_map -> {
|
||||
PassbookMapsFacade.startFullscreenMap(activity)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_share -> {
|
||||
tracker.trackEvent("ui_action", "share", "shared", null)
|
||||
PassExportTaskAndShare(activity, passStore.getPathForID(pass.id)).execute()
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_edit -> {
|
||||
tracker.trackEvent("ui_action", "share", "shared", null)
|
||||
passStore.currentPass = pass
|
||||
activity.startActivityFromClass(PassEditActivity::class.java)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.menu_print -> {
|
||||
PrintHelper.doPrint(activity, pass)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
|
@ -16,8 +16,9 @@ import kotlinx.android.synthetic.main.activity_pass_view_base.*
|
|||
import kotlinx.android.synthetic.main.barcode.*
|
||||
import kotlinx.android.synthetic.main.edit.*
|
||||
import kotlinx.android.synthetic.main.pass_view_extra_data.*
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.compat.HtmlCompat
|
||||
import org.ligi.kaxt.disableRotation
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.maps.PassbookMapsFacade
|
||||
import org.ligi.passandroid.model.PassBitmapDefinitions
|
||||
|
@ -96,7 +97,7 @@ class PassViewActivity : PassViewActivityBase() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
AXT.at(this).disableRotation()
|
||||
disableRotation()
|
||||
|
||||
setContentView(R.layout.activity_pass_view)
|
||||
|
||||
|
@ -123,7 +124,7 @@ class PassViewActivity : PassViewActivityBase() {
|
|||
}
|
||||
|
||||
barcode_img.setOnClickListener {
|
||||
AXT.at(this).startCommonIntent().activityFromClass(FullscreenBarcodeActivity::class.java)
|
||||
startActivityFromClass(FullscreenBarcodeActivity::class.java)
|
||||
}
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.lingala.zip4j.core.ZipFile
|
|||
import net.lingala.zip4j.exception.ZipException
|
||||
import okio.Okio
|
||||
import org.json.JSONObject
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.passandroid.App
|
||||
import org.ligi.passandroid.helper.PassTemplates
|
||||
import org.ligi.passandroid.helper.SafeJSONReader
|
||||
|
@ -34,7 +33,7 @@ object UnzipPassController {
|
|||
fun processInputStream(spec: InputStreamUnzipControllerSpec) {
|
||||
try {
|
||||
val tempFile = File.createTempFile("ins", "pass")
|
||||
AXT.at(spec.inputStreamWithSource.inputStream).toFile(tempFile)
|
||||
spec.inputStreamWithSource.inputStream.copyTo(FileOutputStream(tempFile))
|
||||
processFile(FileUnzipControllerSpec(tempFile.absolutePath, spec))
|
||||
tempFile.delete()
|
||||
} catch (e: Exception) {
|
||||
|
@ -56,7 +55,7 @@ object UnzipPassController {
|
|||
return
|
||||
}
|
||||
|
||||
AXT.at(File(path, "source.obj")).writeObject(spec.source)
|
||||
File(path, "source.obj").bufferedWriter().write(spec.source)
|
||||
|
||||
try {
|
||||
val zipFile = ZipFile(spec.zipFileString)
|
||||
|
@ -72,7 +71,7 @@ object UnzipPassController {
|
|||
|
||||
if (manifestFile.exists()) {
|
||||
try {
|
||||
val readToString = AXT.at(manifestFile).readToString()
|
||||
val readToString = manifestFile.bufferedReader().readText()
|
||||
manifest_json = SafeJSONReader.readJSONSafely(readToString)
|
||||
uuid = manifest_json.getString("pass.json")
|
||||
} catch (e: Exception) {
|
||||
|
@ -82,7 +81,7 @@ object UnzipPassController {
|
|||
|
||||
} else if (espassFile.exists()) {
|
||||
try {
|
||||
val readToString = AXT.at(espassFile).readToString()
|
||||
val readToString = espassFile.bufferedReader().readText()
|
||||
manifest_json = SafeJSONReader.readJSONSafely(readToString)
|
||||
uuid = manifest_json.getString("id")
|
||||
} catch (e: Exception) {
|
||||
|
@ -149,7 +148,7 @@ object UnzipPassController {
|
|||
val rename_file = File(spec.targetPath, uuid)
|
||||
|
||||
if (spec.overwrite && rename_file.exists()) {
|
||||
AXT.at(rename_file).deleteRecursive()
|
||||
rename_file.deleteRecursively()
|
||||
}
|
||||
|
||||
if (!rename_file.exists()) {
|
||||
|
|
|
@ -2,11 +2,13 @@ package org.ligi.passandroid.ui;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import org.ligi.axt.listeners.ActivityFinishingOnClickListener;
|
||||
|
||||
import org.ligi.passandroid.R;
|
||||
import org.ligi.passandroid.model.InputStreamWithSource;
|
||||
import org.ligi.passandroid.model.PassStore;
|
||||
|
||||
import static org.ligi.passandroid.ui.UnzipPassController.FailCallback;
|
||||
import static org.ligi.passandroid.ui.UnzipPassController.InputStreamUnzipControllerSpec;
|
||||
import static org.ligi.passandroid.ui.UnzipPassController.SuccessCallback;
|
||||
|
@ -16,7 +18,12 @@ public class UnzipPassDialog {
|
|||
static void displayError(final Activity activity, final String title, final String err) {
|
||||
new AlertDialog.Builder(activity).setTitle(title)
|
||||
.setMessage(err)
|
||||
.setPositiveButton(android.R.string.ok, new ActivityFinishingOnClickListener(activity))
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
activity.finish();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,12 @@ package org.ligi.passandroid.ui.edit
|
|||
import android.content.Intent
|
||||
import android.support.v4.app.Fragment
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.text.Editable
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageButton
|
||||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import org.ligi.axt.simplifications.SimpleTextWatcher
|
||||
import org.ligi.kaxt.doAfterEdit
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.model.pass.BarCode
|
||||
import org.ligi.passandroid.model.pass.PassBarCodeFormat
|
||||
|
@ -97,11 +96,9 @@ class BarcodeEditController(val rootView: View, internal val context: AppCompatA
|
|||
bindRadio(PassBarCodeFormat.values())
|
||||
|
||||
messageInput.setText(barCode.message)
|
||||
messageInput.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
refresh()
|
||||
}
|
||||
})
|
||||
messageInput.doAfterEdit {
|
||||
refresh()
|
||||
}
|
||||
|
||||
alternativeMessageInput.setText(barCode.alternativeText)
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package org.ligi.passandroid.ui.edit
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.synthetic.main.edit_field.view.*
|
||||
import kotlinx.android.synthetic.main.edit_fields.view.*
|
||||
import org.ligi.axt.simplifications.SimpleTextWatcher
|
||||
import org.ligi.kaxt.doAfterEdit
|
||||
import org.ligi.passandroid.R
|
||||
import org.ligi.passandroid.model.pass.PassField
|
||||
|
||||
|
@ -58,17 +57,13 @@ class FieldsEditFragment : PassandroidFragment() {
|
|||
fields.remove(passField)
|
||||
}
|
||||
|
||||
container.value_field_edit.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
passField.value = s.toString()
|
||||
}
|
||||
})
|
||||
container.value_field_edit.doAfterEdit {
|
||||
passField.value = it.toString()
|
||||
}
|
||||
|
||||
container.label_field_edit.addTextChangedListener(object : SimpleTextWatcher() {
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
passField.label = s.toString()
|
||||
}
|
||||
})
|
||||
container.label_field_edit.doAfterEdit {
|
||||
passField.label = it.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.ligi.passandroid.ui.edit
|
|||
import android.app.Activity
|
||||
import android.app.Activity.RESULT_OK
|
||||
import android.content.Intent
|
||||
import org.ligi.axt.AXT
|
||||
import org.ligi.kaxt.loadImage
|
||||
import org.ligi.passandroid.model.PassBitmapDefinitions
|
||||
import org.ligi.passandroid.model.PassStore
|
||||
import org.ligi.passandroid.model.pass.Pass
|
||||
|
@ -31,7 +31,7 @@ class ImageEditHelper(private val context: Activity, private val passStore: Pass
|
|||
}
|
||||
|
||||
private fun extractImage(imageReturnedIntent: Intent, name: String) {
|
||||
val extractedFile = AXT.at(imageReturnedIntent.data).loadImage(context)
|
||||
val extractedFile = imageReturnedIntent.data.loadImage(context)
|
||||
val pass = passStore.currentPass
|
||||
if (extractedFile != null && pass != null && extractedFile.exists()) {
|
||||
try {
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package org.ligi.passandroid.unittest;
|
||||
|
||||
public class PassFromLibrePassFormatJSON {
|
||||
|
||||
What what;
|
||||
|
||||
public static class What {
|
||||
String description;
|
||||
}
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
package org.ligi.passandroid.unittest;
|
||||
|
||||
import com.squareup.moshi.JsonAdapter;
|
||||
import com.squareup.moshi.Moshi;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import org.junit.Test;
|
||||
import org.ligi.axt.AXT;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ThePassReader {
|
||||
|
||||
@Test
|
||||
public void testMinimalOpass2() throws URISyntaxException, IOException {
|
||||
final FileInputStream fileInputStream = new FileInputStream(new File(getClass().getClassLoader()
|
||||
.getResource("opass_v2/minimal.json")
|
||||
.toURI()));
|
||||
|
||||
|
||||
final Moshi build = new Moshi.Builder().build();
|
||||
final JsonAdapter<PassFromLibrePassFormatJSON> adapter = build.adapter(PassFromLibrePassFormatJSON.class);
|
||||
|
||||
|
||||
final String json = AXT.at(fileInputStream).readToString();
|
||||
final PassFromLibrePassFormatJSON passFromLibrePassFormatJSON = adapter.fromJson(json);
|
||||
|
||||
assertThat(passFromLibrePassFormatJSON.what.description).isEqualTo("Concert Ticket");
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package org.ligi.passandroid.unittest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.junit.Test;
|
||||
import org.ligi.passandroid.reader.TAMMultiPassReader;
|
||||
import org.xml.sax.SAXException;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TheTAMMultiPassParser {
|
||||
|
||||
@Test
|
||||
public void testThatLinksAreParsed() throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
|
||||
final TAMMultiPassReader tested = new TAMMultiPassReader(new FileInputStream(new File(getClass().getClassLoader()
|
||||
.getResource("tam_example_multipass_reply.html")
|
||||
.toURI())));
|
||||
assertThat(tested.getLinks())
|
||||
.containsOnly("?SITK=annon=ymous&actionMobileHtml=&fpdid=4&uci=yes", "?SITK=goo=bar&actionMobileHtml=&fpdid=8&uci=yolo");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatDetectionWorksForPositives() throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
|
||||
final TAMMultiPassReader tested = new TAMMultiPassReader(new FileInputStream(new File(getClass().getClassLoader()
|
||||
.getResource("tam_example_multipass_reply.html")
|
||||
.toURI())));
|
||||
assertThat(tested.isTAMMultiPass()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testThatDetectionDetectsNegatives() throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
|
||||
final TAMMultiPassReader tested = new TAMMultiPassReader("");
|
||||
assertThat(tested.isTAMMultiPass()).isFalse();
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
{
|
||||
"format_version": 2,
|
||||
"what": {
|
||||
"description": "Concert Ticket"
|
||||
},
|
||||
"where": {
|
||||
},
|
||||
"when": {
|
||||
},
|
||||
"secrets": [
|
||||
{
|
||||
"message": "",
|
||||
"transfer": "barcode_QR",
|
||||
"order": 1
|
||||
},
|
||||
{
|
||||
"message": "",
|
||||
"transfer": "text",
|
||||
"order": 2
|
||||
}
|
||||
],
|
||||
"meta": {
|
||||
"app": "org.ligi.passandroid",
|
||||
"id": "28293fd5-d129-4bd3-b935-22746b4b1248",
|
||||
"type": "event"
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
package org.ligi.passandroid;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.LatLngBounds;
|
||||
import com.google.android.gms.maps.model.Marker;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import java.util.List;
|
||||
import org.ligi.axt.AXT;
|
||||
import org.ligi.passandroid.model.pass.PassLocation;
|
||||
import org.ligi.passandroid.ui.PassViewActivityBase;
|
||||
|
||||
public class LocationsMapFragment extends SupportMapFragment {
|
||||
|
||||
private PassViewActivityBase base_activity;
|
||||
public boolean click_to_fullscreen = false;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
base_activity = (PassViewActivityBase) getActivity();
|
||||
|
||||
if (!(getActivity() instanceof PassViewActivityBase)) {
|
||||
throw new IllegalArgumentException("LocationsMapFragment must be used inside a PassViewActivityBase");
|
||||
}
|
||||
|
||||
getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(final GoogleMap map) {
|
||||
|
||||
map.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
|
||||
@Override
|
||||
public void onMapLoaded() {
|
||||
if (click_to_fullscreen) map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
|
||||
@Override
|
||||
public void onMapClick(final LatLng latLng) {
|
||||
App.component().passStore().setCurrentPass(base_activity.currentPass);
|
||||
AXT.at(getActivity()).startCommonIntent().activityFromClass(FullscreenMapActivity.class);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
LatLngBounds.Builder boundBuilder = new LatLngBounds.Builder();
|
||||
|
||||
final List<PassLocation> locations = base_activity.currentPass.getLocations();
|
||||
|
||||
for (PassLocation l : locations) {
|
||||
|
||||
// yea that looks stupid but need to split LatLng free/nonfree - google play services ^^
|
||||
final LatLng latLng = new LatLng(l.getLat(), l.getLon());
|
||||
final MarkerOptions marker = new MarkerOptions().position(latLng).title(l.getNameWithFallback(base_activity.currentPass));
|
||||
map.addMarker(marker);
|
||||
|
||||
|
||||
boundBuilder = boundBuilder.include(latLng);
|
||||
}
|
||||
|
||||
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
|
||||
@Override
|
||||
public void onInfoWindowClick(Marker marker) {
|
||||
final Intent i = new Intent();
|
||||
i.setAction(Intent.ACTION_VIEW);
|
||||
i.setData(Uri.parse("geo:" + marker.getPosition().latitude + "," + marker.getPosition().longitude + "?q=" + marker.getTitle()));
|
||||
getActivity().startActivity(i);
|
||||
}
|
||||
});
|
||||
map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundBuilder.build(), 100));
|
||||
|
||||
// limit zoom-level to 17 - otherwise we could be so zoomed in that it looks buggy
|
||||
map.moveCamera(CameraUpdateFactory.zoomTo(Math.min(17f, map.getCameraPosition().zoom)));
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package org.ligi.passandroid
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.gms.maps.CameraUpdateFactory
|
||||
import com.google.android.gms.maps.SupportMapFragment
|
||||
import com.google.android.gms.maps.model.LatLng
|
||||
import com.google.android.gms.maps.model.LatLngBounds
|
||||
import com.google.android.gms.maps.model.MarkerOptions
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.ui.PassViewActivityBase
|
||||
|
||||
class LocationsMapFragment : SupportMapFragment() {
|
||||
|
||||
private var base_activity: PassViewActivityBase? = null
|
||||
var click_to_fullscreen = false
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val root = super.onCreateView(inflater, container, savedInstanceState)
|
||||
|
||||
base_activity = activity as PassViewActivityBase
|
||||
|
||||
if (activity !is PassViewActivityBase) {
|
||||
throw IllegalArgumentException("LocationsMapFragment must be used inside a PassViewActivityBase")
|
||||
}
|
||||
|
||||
getMapAsync { map ->
|
||||
map.setOnMapLoadedCallback {
|
||||
if (click_to_fullscreen)
|
||||
map.setOnMapClickListener {
|
||||
App.component().passStore().currentPass = base_activity!!.currentPass
|
||||
activity.startActivityFromClass(FullscreenMapActivity::class.java)
|
||||
}
|
||||
|
||||
|
||||
var boundBuilder = LatLngBounds.Builder()
|
||||
|
||||
val locations = base_activity!!.currentPass.locations
|
||||
|
||||
for (l in locations) {
|
||||
|
||||
// yea that looks stupid but need to split LatLng free/nonfree - google play services ^^
|
||||
val latLng = LatLng(l.lat, l.lon)
|
||||
val marker = MarkerOptions().position(latLng).title(l.getNameWithFallback(base_activity!!.currentPass))
|
||||
map.addMarker(marker)
|
||||
|
||||
|
||||
boundBuilder = boundBuilder.include(latLng)
|
||||
}
|
||||
|
||||
map.setOnInfoWindowClickListener { marker ->
|
||||
val i = Intent()
|
||||
i.action = Intent.ACTION_VIEW
|
||||
i.data = Uri.parse("geo:" + marker.position.latitude + "," + marker.position.longitude + "?q=" + marker.title)
|
||||
activity.startActivity(i)
|
||||
}
|
||||
map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundBuilder.build(), 100))
|
||||
|
||||
// limit zoom-level to 17 - otherwise we could be so zoomed in that it looks buggy
|
||||
map.moveCamera(CameraUpdateFactory.zoomTo(Math.min(17f, map.cameraPosition.zoom)))
|
||||
}
|
||||
}
|
||||
|
||||
return root
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package org.ligi.passandroid.maps;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import org.ligi.axt.AXT;
|
||||
import org.ligi.passandroid.FullscreenMapActivity;
|
||||
import org.ligi.passandroid.LocationsMapFragment;
|
||||
import org.ligi.passandroid.R;
|
||||
|
||||
public class PassbookMapsFacade {
|
||||
|
||||
public static boolean init(FragmentActivity context) {
|
||||
final GoogleApiAvailability gapi = GoogleApiAvailability.getInstance();
|
||||
final boolean isGooglePlayServicesAvailable = gapi.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS;
|
||||
|
||||
if (!isGooglePlayServicesAvailable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FragmentTransaction ft = context.getSupportFragmentManager().beginTransaction();
|
||||
LocationsMapFragment locationsMapFragment = new LocationsMapFragment();
|
||||
locationsMapFragment.click_to_fullscreen = true;
|
||||
ft.replace(R.id.map_container, locationsMapFragment);
|
||||
ft.commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void startFullscreenMap(Context context) {
|
||||
AXT.at(context).startCommonIntent().activityFromClass(FullscreenMapActivity.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.ligi.passandroid.maps
|
||||
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v4.app.FragmentActivity
|
||||
import com.google.android.gms.common.ConnectionResult
|
||||
import com.google.android.gms.common.GoogleApiAvailability
|
||||
import org.ligi.kaxt.startActivityFromClass
|
||||
import org.ligi.passandroid.FullscreenMapActivity
|
||||
import org.ligi.passandroid.LocationsMapFragment
|
||||
import org.ligi.passandroid.R
|
||||
|
||||
object PassbookMapsFacade {
|
||||
|
||||
fun init(context: FragmentActivity): Boolean {
|
||||
val gapi = GoogleApiAvailability.getInstance()
|
||||
val isGooglePlayServicesAvailable = gapi.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
|
||||
|
||||
if (!isGooglePlayServicesAvailable) {
|
||||
return false
|
||||
}
|
||||
|
||||
val ft = context.supportFragmentManager.beginTransaction()
|
||||
val locationsMapFragment = LocationsMapFragment()
|
||||
locationsMapFragment.click_to_fullscreen = true
|
||||
ft.replace(R.id.map_container, locationsMapFragment)
|
||||
ft.commit()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun startFullscreenMap(context: Context) {
|
||||
context.startActivityFromClass(FullscreenMapActivity::class.java)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue