-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revised to incorporte BaseActivity + 2 derived Activities
- Loading branch information
1 parent
474c01d
commit dc1a607
Showing
7 changed files
with
230 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.marakana.yambax | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import android.widget.Toast | ||
|
||
interface Command | ||
{ | ||
def void doCommand() | ||
} | ||
|
||
class BaseActivity extends Activity | ||
{ | ||
protected var YambaApplication app | ||
|
||
val prefs = [ | startActivity(new Intent(this, typeof(PrefsActivity)) | ||
.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) ] as Command | ||
|
||
val toggleService = [ | intent = new Intent(this, typeof(UpdaterService)) | ||
if (app.isServiceRunning) | ||
stopService(intent) | ||
else | ||
startService(intent) ] as Command | ||
|
||
val purge = [ | app.clearTimeline | ||
Toast.makeText(this, R.string.msgAllDataPurged, Toast.LENGTH_LONG).show() ] as Command | ||
|
||
val timeline = [ | startActivity(new Intent(this, typeof(TimelineActivity)) | ||
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) | ||
.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)) ] as Command | ||
|
||
val status = [ | startActivity(new Intent(this, typeof(StatusActivity)) | ||
.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT))] as Command | ||
|
||
var commands = #{ R.id.itemPrefs -> prefs, | ||
R.id.itemToggleService -> toggleService, | ||
R.id.itemPurge -> purge, | ||
R.id.itemTimeline -> timeline, | ||
R.id.itemStatus -> status } | ||
|
||
override onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
app = getApplication as YambaApplication | ||
} | ||
|
||
override onCreateOptionsMenu(Menu menu) | ||
{ | ||
getMenuInflater.inflate(R.menu.menu, menu) | ||
true | ||
} | ||
|
||
override onOptionsItemSelected(MenuItem item) | ||
{ | ||
val command = commands.get(item.getItemId) as Command | ||
command.doCommand | ||
true | ||
} | ||
|
||
override onMenuOpened(int featureId, Menu menu) | ||
{ | ||
val toggleItem = menu.findItem(R.id.itemToggleService) | ||
toggleItem.title = if (app.isServiceRunning) R.string.titleServiceStop else R.string.titleServiceStart | ||
toggleItem.icon = if (app.isServiceRunning) android.R.drawable.ic_media_pause else android.R.drawable.ic_media_play | ||
true | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,102 @@ | ||
package com.marakana.yambax | ||
|
||
import android.os.Bundle | ||
import android.widget.ListView | ||
import android.widget.ArrayAdapter | ||
import winterwell.jtwitter.Twitter | ||
import android.content.Context | ||
import java.util.List | ||
import winterwell.jtwitter.Twitter.Status | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.LayoutInflater | ||
import android.widget.TextView | ||
import java.text.DateFormat | ||
import java.text.SimpleDateFormat | ||
|
||
class TimelineActivity extends BaseActivity | ||
{ | ||
var TimelineAdapter timelineAdapter | ||
var timelineUpdate = [| timelineAdapter.notifyDataSetChanged ] as TimelineUpdateListener | ||
|
||
override onCreate(Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.timeline) | ||
timelineAdapter = new TimelineAdapter(this, R.layout.row, app.timeline) | ||
app.updateListener = timelineUpdate | ||
} | ||
|
||
override onStart() | ||
{ | ||
super.onStart | ||
val listTimeline = findViewById(R.id.listTimeline) as ListView | ||
listTimeline.setAdapter(timelineAdapter); | ||
} | ||
} | ||
|
||
class StatusAdapter | ||
{ | ||
@Property View view; | ||
var DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); | ||
|
||
new (Context context, ViewGroup parent, Twitter.Status status) | ||
{ | ||
val LayoutInflater inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater | ||
view = inflater.inflate(R.layout.row, parent, false) | ||
view.id = status.id.intValue | ||
updateControls(status) | ||
} | ||
|
||
def updateControls(Twitter.Status status) | ||
{ | ||
val user = view.findViewById(R.id.textUser) as TextView | ||
val createdAt = view.findViewById(R.id.textCreatedAt) as TextView | ||
val text = view.findViewById(R.id.textText) as TextView | ||
|
||
user.text = status.getUser.name | ||
createdAt.text = df.format(status.createdAt) | ||
text.text = status.text | ||
} | ||
} | ||
|
||
class TimelineAdapter extends ArrayAdapter<Twitter.Status> | ||
{ | ||
var List<Status> timeline | ||
var Context context | ||
|
||
new(Context context, int textViewResourceId, List<Twitter.Status> timeline) | ||
{ | ||
super(context, textViewResourceId, timeline) | ||
this.timeline = timeline | ||
this.context = context | ||
} | ||
|
||
override getView(int position, View convertView, ViewGroup parent) | ||
{ | ||
val status = timeline.get(position) | ||
val item = new StatusAdapter (context, parent, status) | ||
return item.view | ||
} | ||
|
||
override getCount() | ||
{ | ||
return timeline.size | ||
} | ||
|
||
override Twitter.Status getItem(int position) | ||
{ | ||
return timeline.get(position); | ||
} | ||
|
||
override getItemId(int position) | ||
{ | ||
val status = timeline.get(position); | ||
status.id; | ||
} | ||
|
||
override getPosition(Twitter.Status c) | ||
{ | ||
return timeline.indexOf(c); | ||
} | ||
} |
Oops, something went wrong.