Added firebase support for endpoint url and port
This commit is contained in:
parent
6e65216f86
commit
087e22ed3c
3 changed files with 44 additions and 2 deletions
|
@ -7,8 +7,8 @@ android {
|
||||||
applicationId "com.kauron.newssarcher"
|
applicationId "com.kauron.newssarcher"
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 1
|
versionCode 2
|
||||||
versionName "1.0"
|
versionName "1.1"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,7 @@ dependencies {
|
||||||
compile 'com.android.support:support-v4:25.3.1'
|
compile 'com.android.support:support-v4:25.3.1'
|
||||||
compile 'com.android.support:support-vector-drawable:25.3.1'
|
compile 'com.android.support:support-vector-drawable:25.3.1'
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
|
compile 'com.google.firebase:firebase-database:10.2.6'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.google.gms.google-services'
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.kauron.newssarcher;
|
package com.kauron.newssarcher;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
@ -23,6 +24,11 @@ import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.google.firebase.database.DataSnapshot;
|
||||||
|
import com.google.firebase.database.DatabaseError;
|
||||||
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
@ -35,6 +41,38 @@ public class MainActivity extends AppCompatActivity {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
final Context context = this;
|
||||||
|
|
||||||
|
FirebaseDatabase db = FirebaseDatabase.getInstance();
|
||||||
|
final String TAG = "TAG";
|
||||||
|
db.getReference("server_url").addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||||
|
// This method is called once with the initial value and again
|
||||||
|
// whenever data at this location is updated.
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
|
.putString("pref_endpoint", dataSnapshot.getValue(String.class)).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(DatabaseError error) {
|
||||||
|
// Failed to read value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
db.getReference("server_port").addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(context).edit()
|
||||||
|
.putString("pref_port", String.valueOf(dataSnapshot.getValue(Integer.class)))
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(DatabaseError databaseError) {
|
||||||
|
// Failed to read value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
queries = new ArrayList<>();
|
queries = new ArrayList<>();
|
||||||
ListView listView = (ListView) findViewById(R.id.listView);
|
ListView listView = (ListView) findViewById(R.id.listView);
|
||||||
|
|
|
@ -6,6 +6,7 @@ buildscript {
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.2'
|
classpath 'com.android.tools.build:gradle:2.3.2'
|
||||||
|
classpath 'com.google.gms:google-services:3.0.0'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|
Reference in a new issue