Skip to content

Commit

Permalink
bug: try to fix install text
Browse files Browse the repository at this point in the history
  • Loading branch information
androidlover5842 committed Jan 14, 2017
1 parent d8da571 commit b0cfc38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
Expand All @@ -14,6 +12,8 @@
import io.github.otaupdater.otaupdater.util.Config;

import static io.github.otaupdater.otaupdater.util.Config.PermissionRequest;
import static io.github.otaupdater.otaupdater.util.Config.PutStringPreferences;
import static io.github.otaupdater.otaupdater.util.Config.updateFragment;

public class MainActivity extends AppCompatActivity {
private GithubReleasesFragment mFragmentOldRelease;
Expand All @@ -25,9 +25,9 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PutStringPreferences("version", Config.getRomInstalledVersion());
PutStringPreferences(this,"version", Config.getRomInstalledVersion());
this.mFragmentOldRelease = new GithubReleasesFragment().setTargetURL(Config.URL_OLD_RELEASES());
updateFragment(mFragmentOldRelease);
updateFragment(this,mFragmentOldRelease,R.id.content_frame);
mCheckUpdate=(Button)findViewById(R.id.activity_main_check_for_update);
mCheckUpdate.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -39,21 +39,5 @@ public void onClick(View view) {
PermissionRequest(this);
}



protected void updateFragment(Fragment fragment)
{
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

ft.replace(R.id.content_frame, fragment);
ft.commit();
}
public void PutStringPreferences(String Name,String Function){
settings = getSharedPreferences(Name, 0); // 1 - for public mode
editor = settings.edit();
editor.putString(Name, Function);
editor.commit();

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import static io.github.otaupdater.otaupdater.util.Config.DownloadFileName;
import static io.github.otaupdater.otaupdater.util.Config.Downloader;
import static io.github.otaupdater.otaupdater.util.Config.getPreferences;
import static io.github.otaupdater.otaupdater.util.Config.getRomInstalledVersion;
import static io.github.otaupdater.otaupdater.util.Config.uri;

Expand Down Expand Up @@ -77,8 +78,14 @@ public void onClick(View v)
}
if (release.has("version"))
{
boolean i = false;
String p;
p=getPreferences(getContext(),"version");
String InstalledRomVersion= release.getString("version");
if(getRomInstalledVersion().equals(InstalledRomVersion)){
if(p.equals(InstalledRomVersion)){
i=true;
}
if(i==true){
mInstalledText.setVisibility(View.VISIBLE);
}
Log.i("version",InstalledRomVersion+" Rom "+getRomInstalledVersion());
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/io/github/otaupdater/otaupdater/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Environment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;

import com.github.jksiezni.permissive.PermissionsGrantedListener;
Expand All @@ -28,6 +32,8 @@ public class Config {
public static String DownloadFileName;
public static String Tag="RomUpdaterConfig";
public static DownloadManager downloadManager;
public static SharedPreferences settings;
public static SharedPreferences.Editor editor;
public static String URL_OLD_RELEASES(){
String output=ShellExecuter.runAsRoot("getprop ro.updater.oldrelease.url");
return output;
Expand Down Expand Up @@ -129,4 +135,26 @@ public void onPermissionsRefused(String[] permissions) {
.execute(app);
}

public static String getPreferences(Context context,String Name){
String o;
settings = context.getSharedPreferences(Name, 0); // 0 - for private mode
o=settings.getString(Name,null);

return o;
}
public static void PutStringPreferences(Context context,String Name,String Function){
settings = context.getSharedPreferences(Name, 0); // 1 - for public mode
editor = settings.edit();
editor.putString(Name, Function);
editor.commit();

}
public static void updateFragment(FragmentActivity fragmentActivity, Fragment fragment,int id)
{
FragmentTransaction ft = fragmentActivity.getSupportFragmentManager().beginTransaction();
ft.replace(id, fragment);
ft.commit();
}


}

0 comments on commit b0cfc38

Please sign in to comment.