Skip to content

Commit

Permalink
Better view for import/export as described in #189
Browse files Browse the repository at this point in the history
Not tested yet.
  • Loading branch information
Starcommander committed Jul 18, 2022
1 parent d6c3a6b commit 9ba5986
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum FileType { Tracking, Favourites, Setting, Map, Unknown }
CheckBox exFavCb;
CheckBox exTrackCb;
CheckBox exMapsCb;
TextView exFullPathTv;
LinearLayout lImport;
LinearLayout lExport;
LinearLayout lMaps;
Expand All @@ -46,6 +47,7 @@ public enum FileType { Tracking, Favourites, Setting, Map, Unknown }
Button exOk = (Button) findViewById(R.id.exOk);
exSpinner = (Spinner) findViewById(R.id.exSpinner);
exTypeSpinner = (Spinner) findViewById(R.id.exTypeSpinner);
exFullPathTv = (TextView) findViewById(R.id.exFullPathTv);
exSetCb = (CheckBox) findViewById(R.id.exSet_cb);
exFavCb = (CheckBox) findViewById(R.id.exFav_cb);
exTrackCb = (CheckBox) findViewById(R.id.exTrack_cb);
Expand All @@ -67,15 +69,15 @@ public void onClick(View v)
{
if (v.getId()!=R.id.exOk)
{ // Import a pmz file.
String dataDir = exSpinner.getSelectedItem().toString();
String dataDir = ((PathElement)exSpinner.getSelectedItem()).getPath();
String dataFile = ((Button)v).getText().toString();
log("Import from: " + dataDir + "/" + dataFile);
new MapUnzip().unzipImport(new File(dataDir, dataFile).getPath(), this.getApplicationContext());
finish();
return;
}
log("Selected: Export");
String targetDir = exSpinner.getSelectedItem().toString();
String targetDir = ((PathElement)exSpinner.getSelectedItem()).getPath();
if (!new File(targetDir).canWrite())
{
logUser("Error, can not write!");
Expand Down Expand Up @@ -175,7 +177,7 @@ public void onItemSelected(AdapterView<?> av, View view, int i, long l)
lExport.setVisibility(View.GONE);
lImport.setVisibility(View.VISIBLE);
lImport.removeAllViews();
String dataDir = exSpinner.getSelectedItem().toString();
String dataDir = ((PathElement)exSpinner.getSelectedItem()).getPath();
for (String f : new File(dataDir).list())
{
if (!f.endsWith(".pmz")) { continue; }
Expand Down Expand Up @@ -243,8 +245,13 @@ private void logUser(String str)

private void fillSpinner()
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
adapter.addAll(IO.listSelectionPaths(this, false));
ArrayAdapter<PathElement> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line);
int counter = 1;
for (String aPath : IO.listSelectionPaths(this, false))
{
adapter.add(new PathElement(aPath, counter));
counter++;
}
exSpinner.setAdapter(adapter);
exSpinner.setOnItemSelectedListener(this);
}
Expand All @@ -269,5 +276,36 @@ private void fillMapList()
}
exMapsCb.setOnCheckedChangeListener(this);
}

static class PathElement
{
int maxLen = 10;
String path;
String visPath;

public PathElement(String path, int counter)
{
this.path = path;
this.visPath = toVisPath(new File(path).getName(), counter);
}

@Override
public String toString()
{
return visPath;
}

private String toVisPath(String fn, int counter)
{
String ctStr = "(" + counter + ") ";
if (path.length() > (maxLen + 6 + fn.length()))
{
return ctStr + path.substring(0, maxLen) + "... : " + fn;
}
return ctStr + path;
}

public String getPath() { return path; }
}
}

9 changes: 9 additions & 0 deletions PocketMaps/app/src/main/res/layout/activity_export.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/exFullPathTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/my_primary_dark"
android:textSize="22sp"
android:layout_gravity="left"
android:text="Path" />

<Spinner
android:id="@+id/exSpinner"
android:layout_width="fill_parent"
Expand Down

0 comments on commit 9ba5986

Please sign in to comment.