Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Change layout dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed Oct 14, 2014
1 parent 97e28b3 commit 67b9f80
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 20 deletions.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

<activity
android:name=".activites.SettingsActivity"
android:label="@string/app_name"
android:configChanges="screenSize|orientation" />
android:label="@string/app_name" />

<activity
android:name=".activites.AddRepositoryActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
public class MainApplication extends SmallApplication {
private SharedPreferences sharedPreferences;
private MainExpandableAdapter adapter;
private DaoSession daoSession;

@Override
public void onCreate() {
Expand All @@ -56,7 +55,7 @@ public void onCreate() {

// Open database.
DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this, true);
daoSession = databaseHelper.getDaoSession();
DaoSession daoSession = databaseHelper.getDaoSession();
EntryDao entryDao = daoSession.getEntryDao();
RepositoryDao repositoryDao = daoSession.getRepositoryDao();
DatabaseUpgrader.checkAndDoUpgrade(this, daoSession);
Expand Down Expand Up @@ -147,7 +146,7 @@ public void onDestroy() {
}

private void updateRepository(final Repository repository) {
new DownloadAsyncTask(this, daoSession) {
new DownloadAsyncTask(this) {
private ProgressDialog progressDialog;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class AddRepositoryActivity extends Activity {
private TextView aliasTextView;
private Button okButton;
private ProgressBar progressBar;
private DaoSession daoSession;
private RepositoryDao repositoryDao;
private DownloadAsyncTask asyncTask;

Expand All @@ -35,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
aliasTextView = (TextView) findViewById(R.id.repository_alias);
okButton = (Button) findViewById(R.id.ok);
progressBar = (ProgressBar) findViewById(R.id.repository_progressbar);
daoSession = DatabaseHelper.getInstance(this, true).getDaoSession();
DaoSession daoSession = DatabaseHelper.getInstance(this, true).getDaoSession();
repositoryDao = daoSession.getRepositoryDao();

Uri uri = getIntent().getData();
Expand Down Expand Up @@ -92,7 +91,7 @@ public void confirm(View v) {
aliasTextView.setEnabled(false);
okButton.setEnabled(false);

asyncTask = new DownloadAsyncTask(this, daoSession) {
asyncTask = new DownloadAsyncTask(this) {
@Override
protected void onPreExecute() {
super.onPreExecute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -23,7 +22,6 @@ public class SettingsActivity extends Activity implements
private final static String REPOSITORY_FRAGMENT_IS_SHOWING = "REPOSITORY_FRAGMENT_IS_SHOWING";
private RepositoryFragment repositoryFragment;
private boolean tabletLayout;
private DaoSession daoSession;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -32,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {

// Open database.
DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this, true);
daoSession = databaseHelper.getDaoSession();
DaoSession daoSession = databaseHelper.getDaoSession();
DatabaseUpgrader.checkAndDoUpgrade(this, daoSession);

setContentView(R.layout.activity_settings);
Expand All @@ -54,12 +52,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean(REPOSITORY_FRAGMENT_IS_SHOWING,
repositoryFragment != null && !repositoryFragment.isHidden());
repositoryFragment != null && !repositoryFragment.isHidden() & !tabletLayout);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState.getBoolean(REPOSITORY_FRAGMENT_IS_SHOWING, false)) {
if (savedInstanceState.getBoolean(REPOSITORY_FRAGMENT_IS_SHOWING, false) & !tabletLayout) {
onSourceManageClick();
}
}
Expand All @@ -78,10 +76,6 @@ public void onBackStackChanged() {
getFragmentManager().getBackStackEntryCount() > 0);
}

public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

@Override
public boolean onSourceManageClick() {
if (tabletLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void syncRepository(final Repository repository) {
.findViewWithTag(repository).getParent();
final ProgressBar progressBar =
(ProgressBar) itemView.findViewById(R.id.repository_progressbar);
new DownloadAsyncTask(context, daoSession) {
new DownloadAsyncTask(context) {
@Override
protected void onPreExecute() {
super.onPreExecute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.sorz.lab.smallcloudemoji.R;
import org.sorz.lab.smallcloudemoji.db.Category;
import org.sorz.lab.smallcloudemoji.db.DaoSession;
import org.sorz.lab.smallcloudemoji.db.DatabaseHelper;
import org.sorz.lab.smallcloudemoji.db.Entry;
import org.sorz.lab.smallcloudemoji.db.Repository;
import org.sorz.lab.smallcloudemoji.exceptions.LoadingCancelException;
Expand Down Expand Up @@ -45,10 +46,10 @@ public class DownloadAsyncTask extends AsyncTask<Repository, Integer, Integer> {
protected static final int RESULT_ERROR_UNSUPPORTED_FORMAT = 7;


public DownloadAsyncTask(Context context, DaoSession daoSession) {
public DownloadAsyncTask(Context context) {
super();
this.context = context;
this.daoSession = daoSession;
daoSession = DatabaseHelper.getInstance(context, true).getDaoSession();
}

@Override
Expand Down Expand Up @@ -120,6 +121,7 @@ public boolean onEntryLoaded(Entry entry) {
e.printStackTrace();
return RESULT_ERROR_UNKNOWN;
} finally {
DatabaseHelper.getInstance(context).close();
try {
if (inputStream != null)
inputStream.close();
Expand Down

0 comments on commit 67b9f80

Please sign in to comment.