This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
3,165 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/AbstractListActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package nodomain.freeyourgadget.gadgetbridge.activities; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.widget.Toolbar; | ||
import android.widget.ListView; | ||
import android.widget.Toast; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import nodomain.freeyourgadget.gadgetbridge.GBApplication; | ||
import nodomain.freeyourgadget.gadgetbridge.R; | ||
import nodomain.freeyourgadget.gadgetbridge.adapter.AbstractItemAdapter; | ||
import nodomain.freeyourgadget.gadgetbridge.adapter.ItemWithDetailsAdapter; | ||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; | ||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; | ||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao; | ||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; | ||
import nodomain.freeyourgadget.gadgetbridge.model.GenericItem; | ||
import nodomain.freeyourgadget.gadgetbridge.model.ItemWithDetails; | ||
import nodomain.freeyourgadget.gadgetbridge.util.GB; | ||
|
||
public abstract class AbstractListActivity<T> extends AbstractGBActivity { | ||
private AbstractItemAdapter<T> itemAdapter; | ||
private ListView itemListView; | ||
|
||
public void setItemAdapter(AbstractItemAdapter<T> itemAdapter) { | ||
this.itemAdapter = itemAdapter; | ||
itemListView.setAdapter(itemAdapter); | ||
} | ||
|
||
protected void refresh() { | ||
this.itemAdapter.loadItems(); | ||
} | ||
|
||
public AbstractItemAdapter<T> getItemAdapter() { | ||
return itemAdapter; | ||
} | ||
|
||
public ListView getItemListView() { | ||
return itemListView; | ||
} | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
setContentView(R.layout.activity_list); | ||
itemListView = (ListView) findViewById(R.id.itemListView); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
.../main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package nodomain.freeyourgadget.gadgetbridge.activities; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.view.ContextMenu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import android.widget.Toast; | ||
|
||
import java.io.IOException; | ||
|
||
import nodomain.freeyourgadget.gadgetbridge.adapter.ActivitySummariesAdapter; | ||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; | ||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummary; | ||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils; | ||
import nodomain.freeyourgadget.gadgetbridge.util.GB; | ||
|
||
public class ActivitySummariesActivity extends AbstractListActivity<BaseActivitySummary> { | ||
|
||
private int selectedIndex; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setItemAdapter(new ActivitySummariesAdapter(this)); | ||
|
||
getItemListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | ||
Object item = parent.getItemAtPosition(position); | ||
if (item != null) { | ||
ActivitySummary summary = (ActivitySummary) item; | ||
String gpxTrack = summary.getGpxTrack(); | ||
if (gpxTrack != null) { | ||
showTrack(gpxTrack); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
|
||
getItemListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { | ||
@Override | ||
public void onCreateContextMenu(ContextMenu menu, View v, final ContextMenu.ContextMenuInfo menuInfo) { | ||
MenuItem delete = menu.add("Delete"); | ||
delete.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { | ||
@Override | ||
public boolean onMenuItemClick(MenuItem item) { | ||
deleteItemAt(selectedIndex); | ||
return true; | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
getItemListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { | ||
@Override | ||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { | ||
selectedIndex = position; | ||
return getItemListView().showContextMenu(); | ||
} | ||
}); | ||
} | ||
|
||
private void deleteItemAt(int position) { | ||
BaseActivitySummary item = getItemAdapter().getItem(position); | ||
if (item != null) { | ||
item.delete(); | ||
getItemAdapter().remove(item); | ||
refresh(); | ||
} | ||
} | ||
|
||
private void showTrack(String gpxTrack) { | ||
try { | ||
AndroidUtils.viewFile(gpxTrack, Intent.ACTION_VIEW, this); | ||
} catch (IOException e) { | ||
GB.toast(this, "Unable to display GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.