Permalink
Browse files

implemented (real) entry io and a few bugs fixed.

  • Loading branch information...
1 parent e2a8d09 commit 16647af8ede3ba5932496d6508ff64d6dc1eea40 @0ffffffffh committed Jun 24, 2011
View
2 AndroidManifest.xml
@@ -22,7 +22,7 @@
<service android:enabled="true" android:name=".Service.ListStateUpdaterService">
<intent-filter>
- <action android:name=".Service.ListStateUpdaterService" />
+ <action android:name="com.android.Eksigator.Service.ListStateUpdaterService" />
</intent-filter>
</service>
View
10 src/com/android/Eksigator/Cache/FollowListCache.java
@@ -143,19 +143,19 @@ private static boolean writeCache(FollowListCache cache) {
return true;
}
- public static FollowListCache readCache(Context context, boolean commitEnabled) {
+ public static FollowListCache readCache(Context context, boolean commitEnabled, boolean workerEnable) {
FollowListCache cacheObj = null;
try {
FileInputStream fsi = context.openFileInput("gatorcache.cache");
ObjectInputStream ois = new ObjectInputStream(fsi);
cacheObj = (FollowListCache)ois.readObject();
- cacheObj.init(true);
+ cacheObj.init(workerEnable);
}
catch (Exception e) {
e.printStackTrace();
DebugLog.writeCache(DebugType.DT_ERR,"cache reading failed. (%s)", e.getMessage());
- cacheObj = new FollowListCache(true);
+ cacheObj = new FollowListCache(workerEnable);
}
cacheObj.commitModeEnabled = commitEnabled;
@@ -262,6 +262,10 @@ public void registerRefreshRequestHandler(CacheRefreshRequestHandler handler) {
cacheRequestHandler = handler;
}
+ public void setCommitState(boolean state) {
+ commitModeEnabled = state;
+ }
+
public void addAddToListCommit(String title) {
commits.addCommit(Commiter.CommitType.ADDTOLIST, title);
}
View
8 src/com/android/Eksigator/Core/Eksigator.java
@@ -122,7 +122,7 @@ public Eksigator(Context context, Settings setting, boolean cacheEnabled) {
this.failCause = FailCause.NOT_FAILED;
if (cacheEnabled) {
- cache = FollowListCache.readCache(context,setting.getCommitEnableStatus());
+ cache = FollowListCache.readCache(context,setting.getCommitEnableStatus(),true);
cache.registerRefreshRequestHandler(new CacheRefreshRequestHandler() {
@Override
@@ -184,6 +184,7 @@ public final boolean isLoaded() {
cache.addSetItemAsReadCommit(title.getTitle());
return null;
}
+
}
return callApiMethod("setItemAsRead",title.getTitle());
@@ -224,6 +225,11 @@ public void sendMessageToCache(CacheMessage message) {
}
}
+ public void setCommitingState(boolean enabled) {
+ if (cache != null)
+ cache.setCommitState(enabled);
+ }
+
public final boolean hasFailed() {
return failCause != FailCause.NOT_FAILED;
}
View
44 src/com/android/Eksigator/MainActivity.java
@@ -80,7 +80,7 @@ protected void onPostExecute(Void v) {
}
- private void loadTitles() {
+ private boolean loadTitles() {
List<TitleModel> titles = null;
@@ -94,12 +94,15 @@ private void loadTitles() {
}
else {
Toast.makeText(this, "öteki tarafta birşey yok :)", Toast.LENGTH_SHORT).show();
+ return false;
}
}
else {
DebugLog.writeActivity(DebugType.DT_INFO, "getting list from gatorObject");
gatorObject.getList();
}
+
+ return true;
}
private boolean refreshTitles(List<TitleModel> refreshList, boolean listIsPart) {
@@ -274,27 +277,28 @@ public void onClick(DialogInterface dialog, int which) {
@Override
public void onClick(View v) {
- isUnreadsActive = !isUnreadsActive;
String buttonText;
- Drawable butIcon;
-
- if (isUnreadsActive) {
- butIcon = notUpdatedBtnIcon;
- buttonText = "Güncel olmayan başlıkları göster";
- }
- else {
- butIcon = updatedBtnIcon;
- buttonText = "Güncel başlıkları göster";
- }
-
-
+ Drawable butIcon;
+
onlySwapList = true;
- loadTitles();
-
- btnToggleListType.setCompoundDrawables(butIcon, null, null, null);
-
- btnToggleListType.setText(buttonText);
+ isUnreadsActive = !isUnreadsActive;
+ if (loadTitles()) {
+ if (isUnreadsActive) {
+ butIcon = notUpdatedBtnIcon;
+ buttonText = "Güncel olmayan başlıkları göster";
+ }
+ else {
+ butIcon = updatedBtnIcon;
+ buttonText = "Güncel başlıkları göster";
+ }
+
+ btnToggleListType.setCompoundDrawables(butIcon, null, null, null);
+
+ btnToggleListType.setText(buttonText);
+ }
+ else
+ isUnreadsActive = !isUnreadsActive;
}
});
@@ -310,7 +314,7 @@ public void onClick(View v) {
}
else {
DebugLog.writeActivity(DebugType.DT_INFO, "The service was automatically started. Now it'll try to interconnect");
- serviceIntent = new Intent("com.android.Eksigator.ListStateUpdaterService");
+ serviceIntent = new Intent("com.android.Eksigator.Service.ListStateUpdaterService");
}
View
8 src/com/android/Eksigator/Service/AutoServiceStarter.java
@@ -13,11 +13,9 @@
@Override
public void onReceive(Context context, Intent intent) {
DebugLog.writeService(DebugType.DT_INFO, "Booting ek$igator background service");
- Intent servIntent = new Intent();
- Bundle servIoBundle = new Bundle();
- servIntent.putExtras(servIoBundle);
- servIntent.setAction("com.android.EksigatorService.ListStateUpdaterService");
+ Intent servIntent = new Intent("com.android.Eksigator.Service.ListStateUpdaterService");
+ //Bundle servIoBundle = new Bundle();
+ //servIntent.putExtras(servIoBundle);
context.startService(servIntent);
}
-
}
View
32 src/com/android/Eksigator/Service/ListStateUpdaterService.java
@@ -1,6 +1,5 @@
package com.android.Eksigator.Service;
-import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@@ -34,7 +33,7 @@ ListStateUpdaterService getService() {
GatorBinder binderObj = new GatorBinder();
Timer delayedOp = new Timer();
- List<TitleModel> lastTitles;
+ PartedTitleListContainer lastTitleList;
MessagePassing messager;
Eksigator servGator;
FollowListCache cache;
@@ -57,25 +56,23 @@ private void sendNotification(String ticker, String title, String msg) {
notifyMgr.notify(android.os.Process.myPid(), notification);
}
- //TODO: bu kisim eksik gibi. test edilmesi lazim
private int checkForNewestTitleAvailable() {
PartedTitleListContainer newListPart = new PartedTitleListContainer(servGator.getTitles());
- PartedTitleListContainer lastListPart = new PartedTitleListContainer(lastTitles);
+ int newestTitleCount=0;
- if (!lastListPart.isUsable()) {
- if (newListPart.getUnreadedTitles().size() > 0) {
- lastTitles = servGator.getTitles();
- cache.setList(lastTitles);
- return newListPart.getUnreadedTitles().size();
- }
- }
- else {
- if (newListPart.getUnreadedTitles().size() > lastListPart.getUnreadedTitles().size()) {
- return newListPart.getUnreadedTitles().size() - lastListPart.getUnreadedTitles().size();
+ for (TitleModel title : newListPart.getUnreadedTitles()) {
+ for (TitleModel prevTitle : lastTitleList.getUnreadedTitles()) {
+ if (!prevTitle.getTitle().equals(title.getTitle())) {
+ newestTitleCount++;
+ break;
+ }
}
}
- return 0;
+ if (newestTitleCount > 0)
+ lastTitleList.setList(servGator.getTitles());
+
+ return newestTitleCount;
}
private void internalStart() {
@@ -86,9 +83,12 @@ private void internalStart() {
setting = Settings.readPreferences(this,false);
- cache = new FollowListCache(false,this);
+ cache = FollowListCache.readCache(this, false, false);
servGator = new Eksigator(this,setting,false);
+ lastTitleList = new PartedTitleListContainer(cache.getCachedList());
+
+
delayedOp.scheduleAtFixedRate(new TimerTask() {
@Override
View
17 src/com/android/Eksigator/TitleListManagerActivity.java
@@ -85,8 +85,9 @@ public final Object getExtra2() {
}
private void addTitleToList(String title) {
- //TODO: Eksigator'a eklenme kodu yazilacak
- titles.add(new TitleModel(title,290));
+ TitleModel titleObj = new TitleModel(title,0);
+ gatorObject.addToList(titleObj);
+ titles.add(titleObj);
MainActivity.refreshOnResume = true;
}
@@ -114,8 +115,7 @@ protected Void doInBackground(Integer... params) {
DebugLog.writeActivity(DebugType.DT_DEBUG, "removing %s", title.getTitle());
- //TODO: Silme islemini yapan kod yazilacak
- Helper.delay(2000);
+ gatorObject.removeFromList(title);
publishProgress();
}
@@ -150,6 +150,8 @@ public void onCreate(Bundle savedInstanceState) {
if (MainActivity.sharedGatorObject != null) {
gatorObject = MainActivity.sharedGatorObject;
+ gatorObject.setCommitingState(false);
+
titles = gatorObject.getTitles();
dataAdapter = new TitleAdapter(this,titles,true);
@@ -160,6 +162,13 @@ public void onCreate(Bundle savedInstanceState) {
}
}
+ public void onDestroy() {
+ super.onDestroy();
+
+ if (gatorObject != null)
+ gatorObject.setCommitingState(true);
+ }
+
public boolean onCreateOptionsMenu(Menu m) {
m.add(0, M_ADDNEWTITLE, 0, "Başlık Ekle").setIcon(android.R.drawable.ic_input_add);
m.add(0, M_REMOVEFROMLIST, 0, "Seçilileri Çıkar").setIcon(android.R.drawable.ic_delete);

0 comments on commit 16647af

Please sign in to comment.