mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-30 19:05:02 +01:00
database bugfix
check network state
This commit is contained in:
parent
b148cb6e97
commit
89af291659
@ -2,8 +2,6 @@ package org.nuclearfog.twidda.backend;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -59,17 +57,16 @@ public class Registration extends AsyncTask<String, Void, Boolean> {
|
|||||||
if(success) {
|
if(success) {
|
||||||
connect.setResult(Activity.RESULT_OK);
|
connect.setResult(Activity.RESULT_OK);
|
||||||
connect.finish();
|
connect.finish();
|
||||||
} else {
|
} else if (errorMessage != null) {
|
||||||
try {
|
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW);
|
|
||||||
i.setData(Uri.parse(redirectionURL));
|
|
||||||
connect.startActivity(i);
|
|
||||||
} catch (Exception err) {
|
|
||||||
Toast.makeText(connect, "Keine Verbindung!", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(errorMessage != null) {
|
|
||||||
Toast.makeText(connect,errorMessage,Toast.LENGTH_LONG).show();
|
Toast.makeText(connect,errorMessage,Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
ui.get().connect(redirectionURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnConnect {
|
||||||
|
void connect(String link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public class AppDatabase extends SQLiteOpenHelper
|
|||||||
"statusregister INTEGER, source TEXT, FOREIGN KEY (userID) REFERENCES user(userID));";
|
"statusregister INTEGER, source TEXT, FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||||
|
|
||||||
private static final String favoriteTable = "CREATE TABLE IF NOT EXISTS favorit (" +
|
private static final String favoriteTable = "CREATE TABLE IF NOT EXISTS favorit (" +
|
||||||
"ownerID INTEGER, tweetID INTEGER UNIQUE," +
|
"ownerID INTEGER, tweetID INTEGER PRIMARY KEY," +
|
||||||
"FOREIGN KEY (ownerID) REFERENCES user(userID)," +
|
"FOREIGN KEY (ownerID) REFERENCES user(userID)," +
|
||||||
"FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));";
|
"FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));";
|
||||||
|
|
||||||
@ -38,8 +38,10 @@ public class AppDatabase extends SQLiteOpenHelper
|
|||||||
public void onCreate(SQLiteDatabase db) {
|
public void onCreate(SQLiteDatabase db) {
|
||||||
db.execSQL(userTable);
|
db.execSQL(userTable);
|
||||||
db.execSQL(tweetTable);
|
db.execSQL(tweetTable);
|
||||||
db.execSQL(trendTable);
|
|
||||||
db.execSQL(favoriteTable);
|
db.execSQL(favoriteTable);
|
||||||
|
|
||||||
|
db.execSQL(trendTable);
|
||||||
db.execSQL(errorTable);
|
db.execSQL(errorTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,12 +49,11 @@ public class AppDatabase extends SQLiteOpenHelper
|
|||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "user");
|
db.execSQL("DROP TABLE IF EXISTS " + "user");
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "tweet");
|
db.execSQL("DROP TABLE IF EXISTS " + "tweet");
|
||||||
|
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "favorit");
|
db.execSQL("DROP TABLE IF EXISTS " + "favorit");
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "timeline");
|
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "mentionTable");
|
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "trend");
|
db.execSQL("DROP TABLE IF EXISTS " + "trend");
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + "error");
|
db.execSQL("DROP TABLE IF EXISTS " + "error");
|
||||||
onCreate(db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ public class DatabaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Nutzer speichern
|
* Nutzer speichern
|
||||||
*
|
|
||||||
* @param user Nutzer Information
|
* @param user Nutzer Information
|
||||||
*/
|
*/
|
||||||
public void storeUser(TwitterUser user) {
|
public void storeUser(TwitterUser user) {
|
||||||
@ -47,7 +46,6 @@ public class DatabaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Home Timeline speichern
|
* Home Timeline speichern
|
||||||
*
|
|
||||||
* @param home Tweet Liste
|
* @param home Tweet Liste
|
||||||
*/
|
*/
|
||||||
public void storeHomeTimeline(List<Tweet> home) {
|
public void storeHomeTimeline(List<Tweet> home) {
|
||||||
@ -61,7 +59,6 @@ public class DatabaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Erwähnungen speichern
|
* Erwähnungen speichern
|
||||||
*
|
|
||||||
* @param mentions Tweet Liste
|
* @param mentions Tweet Liste
|
||||||
*/
|
*/
|
||||||
public void storeMentions(List<Tweet> mentions) {
|
public void storeMentions(List<Tweet> mentions) {
|
||||||
@ -328,7 +325,14 @@ public class DatabaseAdapter {
|
|||||||
*/
|
*/
|
||||||
public void removeFavorite(long tweetId) {
|
public void removeFavorite(long tweetId) {
|
||||||
SQLiteDatabase db = dataHelper.getWritableDatabase();
|
SQLiteDatabase db = dataHelper.getWritableDatabase();
|
||||||
db.delete("favorit", "tweetID=" + tweetId + " AND ownerID="+homeId,null);//todo change flag
|
db.delete("favorit", "tweetID=" + tweetId + " AND ownerID=" + homeId, null);
|
||||||
|
|
||||||
|
int register = getStatRegister(db, tweetId);
|
||||||
|
register &= ~favoritedmask;
|
||||||
|
|
||||||
|
ContentValues status = new ContentValues();
|
||||||
|
status.put("statusregister", register);
|
||||||
|
db.update("tweet", status, "tweet.tweetID=" + tweetId, null);
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,8 +381,8 @@ public class DatabaseAdapter {
|
|||||||
long replyUserId = cursor.getLong(index);
|
long replyUserId = cursor.getLong(index);
|
||||||
index = cursor.getColumnIndex("statusregister");
|
index = cursor.getColumnIndex("statusregister");
|
||||||
int statusregister = cursor.getInt(index);
|
int statusregister = cursor.getInt(index);
|
||||||
boolean favorited = (statusregister & 1) == 1;
|
boolean favorited = (statusregister & 1) == favoritedmask;
|
||||||
boolean retweeted = (statusregister & 2) == 2;
|
boolean retweeted = (statusregister & 2) == retweetedmask;
|
||||||
|
|
||||||
String[] medias = parseMedia(medialinks);
|
String[] medias = parseMedia(medialinks);
|
||||||
|
|
||||||
@ -423,7 +427,7 @@ public class DatabaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void storeStatus(Tweet tweet, int newStatusregister, SQLiteDatabase db) {
|
private void storeStatus(Tweet tweet, int newStatusRegister, SQLiteDatabase db) {
|
||||||
ContentValues status = new ContentValues();
|
ContentValues status = new ContentValues();
|
||||||
TwitterUser mUser = tweet.user;
|
TwitterUser mUser = tweet.user;
|
||||||
Tweet rtStat = tweet.embedded;
|
Tweet rtStat = tweet.embedded;
|
||||||
@ -455,14 +459,19 @@ public class DatabaseAdapter {
|
|||||||
}
|
}
|
||||||
status.put("media",media.toString());
|
status.put("media",media.toString());
|
||||||
int statusregister = getStatRegister(db,tweet.tweetID);
|
int statusregister = getStatRegister(db,tweet.tweetID);
|
||||||
statusregister |= newStatusregister;
|
statusregister |= newStatusRegister;
|
||||||
if (tweet.favorized)
|
if (tweet.favorized)
|
||||||
statusregister |= 1;
|
statusregister |= favoritedmask;
|
||||||
|
else
|
||||||
|
statusregister &= ~favoritedmask;
|
||||||
|
|
||||||
if (tweet.retweeted)
|
if (tweet.retweeted)
|
||||||
statusregister |= 1 << 1;
|
statusregister |= retweetedmask;
|
||||||
|
else
|
||||||
|
statusregister &= ~retweetedmask;
|
||||||
|
|
||||||
status.put("statusregister", statusregister);
|
status.put("statusregister", statusregister);
|
||||||
db.insertWithOnConflict("tweet",null, status, CONFLICT_REPLACE);
|
db.insertWithOnConflict("tweet", null, status, CONFLICT_IGNORE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@ package org.nuclearfog.twidda.window;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@ -10,14 +14,15 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import org.nuclearfog.twidda.R;
|
import org.nuclearfog.twidda.R;
|
||||||
import org.nuclearfog.twidda.backend.Registration;
|
import org.nuclearfog.twidda.backend.Registration;
|
||||||
|
import org.nuclearfog.twidda.backend.Registration.OnConnect;
|
||||||
|
|
||||||
|
|
||||||
public class LoginPage extends Activity implements OnClickListener {
|
public class LoginPage extends Activity implements OnClickListener, OnConnect {
|
||||||
|
|
||||||
private EditText pin;
|
private EditText pin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle b){
|
protected void onCreate(Bundle b) {
|
||||||
super.onCreate(b);
|
super.onCreate(b);
|
||||||
setContentView(R.layout.loginpage);
|
setContentView(R.layout.loginpage);
|
||||||
pin = findViewById(R.id.pin);
|
pin = findViewById(R.id.pin);
|
||||||
@ -63,4 +68,18 @@ public class LoginPage extends Activity implements OnClickListener {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect(String link) {
|
||||||
|
ConnectivityManager mConnect = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
if (mConnect != null && mConnect.getActiveNetworkInfo() != null) {
|
||||||
|
if (mConnect.getActiveNetworkInfo().isConnected()) {
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW);
|
||||||
|
i.setData(Uri.parse(link));
|
||||||
|
startActivity(i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this, "Keine Verbindung!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user