diff --git a/TwitterApp/README.md b/TwitterApp/README.md new file mode 100644 index 000000000000..5c9876335b58 --- /dev/null +++ b/TwitterApp/README.md @@ -0,0 +1,13 @@ +##Tweeter AAP. +###This app is socail media app that allows people to share thier photo's,status, and follow other people. +####The complete tutorial how to build it is on [UDEMY Android 7](https://www.udemy.com/android-tutorial-for-beginners/?instructorPreviewMode=guest) + + + +![main](http://attach.alruabye.net/androidTutorialForBeginners/tweeterapp/login.png) + + +![main](http://attach.alruabye.net/androidTutorialForBeginners/tweeterapp/tweet1.png) + +![main](http://attach.alruabye.net/androidTutorialForBeginners/tweeterapp/tweet2.png) + diff --git a/TwitterApp/TwitterDem/.gitignore b/TwitterApp/TwitterDem/.gitignore old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/.idea/misc.xml b/TwitterApp/TwitterDem/.idea/misc.xml index 84cfd6708077..ede8dd6faf04 100644 --- a/TwitterApp/TwitterDem/.idea/misc.xml +++ b/TwitterApp/TwitterDem/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/TwitterApp/TwitterDem/.idea/modules.xml b/TwitterApp/TwitterDem/.idea/modules.xml index 2bc9a4255897..668c33c340dd 100644 --- a/TwitterApp/TwitterDem/.idea/modules.xml +++ b/TwitterApp/TwitterDem/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/TwitterApp/TwitterDem/app/.gitignore b/TwitterApp/TwitterDem/app/.gitignore old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/build.gradle b/TwitterApp/TwitterDem/app/build.gradle old mode 100644 new mode 100755 index 8d0f545bf74c..d9d1914c779d --- a/TwitterApp/TwitterDem/app/build.gradle +++ b/TwitterApp/TwitterDem/app/build.gradle @@ -4,7 +4,7 @@ android { compileSdkVersion 25 buildToolsVersion "25.0.0" defaultConfig { - applicationId "com.alrubaye.twitterdem" + applicationId "com.alrubaye.twitterdemstart" minSdkVersion 12 targetSdkVersion 25 versionCode 1 diff --git a/TwitterApp/TwitterDem/app/google-services.json b/TwitterApp/TwitterDem/app/google-services.json index cc9148e82ceb..8030cf38a112 100644 --- a/TwitterApp/TwitterDem/app/google-services.json +++ b/TwitterApp/TwitterDem/app/google-services.json @@ -1,35 +1,35 @@ { "project_info": { - "project_number": "21845150751", - "firebase_url": "https://firbasedemo-6228f.firebaseio.com", - "project_id": "firbasedemo-6228f", - "storage_bucket": "firbasedemo-6228f.appspot.com" + "project_number": "583184855128", + "firebase_url": "https://twitter-app-f69e8.firebaseio.com", + "project_id": "twitter-app-f69e8", + "storage_bucket": "twitter-app-f69e8.appspot.com" }, "client": [ { "client_info": { - "mobilesdk_app_id": "1:21845150751:android:8592e90db472ebb7", + "mobilesdk_app_id": "1:583184855128:android:07389f7d5e0bcd17", "android_client_info": { - "package_name": "com.hussienalrubaye.androidfirebase" + "package_name": "com.alrubaye.twitterdemstart" } }, "oauth_client": [ { - "client_id": "21845150751-tiq6jqsk2ndfvlvgtnlc659jsakg5csn.apps.googleusercontent.com", + "client_id": "583184855128-qqqqlqmkih0ocqcu1rl0kjdcmq20uk7c.apps.googleusercontent.com", "client_type": 1, "android_info": { - "package_name": "com.hussienalrubaye.androidfirebase", + "package_name": "com.alrubaye.twitterdemstart", "certificate_hash": "76A07B52241638F10FB6D3CF8F6B855F929169DC" } }, { - "client_id": "21845150751-m2e88crhtgshikohp6jmeln4o4ut014k.apps.googleusercontent.com", + "client_id": "583184855128-u7mnqrfajk8p3risq27mm7n339m8i41j.apps.googleusercontent.com", "client_type": 3 } ], "api_key": [ { - "current_key": "AIzaSyBrmRClRWJF_SsRTnHUCufUo6808FJFa7I" + "current_key": "AIzaSyDBd05ZSdlPaklsg_QiRk6bLNzZe7HUfyA" } ], "services": { @@ -40,7 +40,7 @@ "status": 2, "other_platform_oauth_client": [ { - "client_id": "21845150751-m2e88crhtgshikohp6jmeln4o4ut014k.apps.googleusercontent.com", + "client_id": "583184855128-u7mnqrfajk8p3risq27mm7n339m8i41j.apps.googleusercontent.com", "client_type": 3 } ] @@ -49,76 +49,6 @@ "status": 2 } } - }, - { - "client_info": { - "mobilesdk_app_id": "1:21845150751:android:679da90dbe15c5b2", - "android_client_info": { - "package_name": "com.alrubye.firstapp" - } - }, - "oauth_client": [ - { - "client_id": "21845150751-5tk4fg7c1k9l81ll5q8lihmtnp1olt0c.apps.googleusercontent.com", - "client_type": 1, - "android_info": { - "package_name": "com.alrubye.firstapp", - "certificate_hash": "76A07B52241638F10FB6D3CF8F6B855F929169DC" - } - }, - { - "client_id": "21845150751-m2e88crhtgshikohp6jmeln4o4ut014k.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyBrmRClRWJF_SsRTnHUCufUo6808FJFa7I" - } - ], - "services": { - "analytics_service": { - "status": 1 - }, - "appinvite_service": { - "status": 1, - "other_platform_oauth_client": [] - }, - "ads_service": { - "status": 2 - } - } - }, - { - "client_info": { - "mobilesdk_app_id": "1:21845150751:android:3162a499db69de48", - "android_client_info": { - "package_name": "com.alrubaye.twitterdem" - } - }, - "oauth_client": [ - { - "client_id": "21845150751-m2e88crhtgshikohp6jmeln4o4ut014k.apps.googleusercontent.com", - "client_type": 3 - } - ], - "api_key": [ - { - "current_key": "AIzaSyBrmRClRWJF_SsRTnHUCufUo6808FJFa7I" - } - ], - "services": { - "analytics_service": { - "status": 1 - }, - "appinvite_service": { - "status": 1, - "other_platform_oauth_client": [] - }, - "ads_service": { - "status": 2 - } - } } ], "configuration_version": "1" diff --git a/TwitterApp/TwitterDem/app/proguard-rules.pro b/TwitterApp/TwitterDem/app/proguard-rules.pro old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/androidTest/java/com/alrubaye/twitterdem/ExampleInstrumentedTest.java b/TwitterApp/TwitterDem/app/src/androidTest/java/com/alrubaye/twitterdem/ExampleInstrumentedTest.java old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/AndroidManifest.xml b/TwitterApp/TwitterDem/app/src/main/AndroidManifest.xml old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/AdapterItems.java b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/AdapterItems.java old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/Login.java b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/Login.java old mode 100644 new mode 100755 index 4c1213e9b0bf..2c9aa7f9f6da --- a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/Login.java +++ b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/Login.java @@ -51,8 +51,6 @@ public class Login extends AppCompatActivity { EditText etEmail; EditText etPassword; ImageView ivUserImage; - int RESULT_LOAD_IMAGE=111; //any number for tag - //1- define private static final String TAG = "AnonymousAuth"; // [START declare_auth] @@ -73,12 +71,11 @@ protected void onCreate(Bundle savedInstanceState) { @Override public void onClick(View view) { - CheckUserPermsions(); + CheckUserPermsions(); } }); - //2- initiailze OnCreate() - // [START initialize_auth] + mAuth = FirebaseAuth.getInstance(); // [END initialize_auth] @@ -98,36 +95,17 @@ public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { } }; } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { - Uri selectedImage = data.getData(); - String[] filePathColumn = {MediaStore.Images.Media.DATA}; - - Cursor cursor = getContentResolver().query(selectedImage, - filePathColumn, null, null, null); - cursor.moveToFirst(); - - int columnIndex = cursor.getColumnIndex(filePathColumn[0]); - String picturePath = cursor.getString(columnIndex); - cursor.close(); - ivUserImage.setImageBitmap(BitmapFactory.decodeFile(picturePath)); - - } - } public void buLogin(View view) { showProgressDialog(); FirebaseStorage storage=FirebaseStorage.getInstance(); // Create a storage reference from our app - StorageReference storageRef = storage.getReferenceFromUrl("gs://firbasedemo-6228f.appspot.com"); + StorageReference storageRef = storage.getReferenceFromUrl("gs://twitter-app-f69e8.appspot.com"); DateFormat df = new SimpleDateFormat("ddMMyyHHmmss"); Date dateobj = new Date(); - // System.out.println(df.format(dateobj)); + // System.out.println(df.format(dateobj)); // Create a reference to "mountains.jpg" - final String ImagePath= df.format(dateobj) +".jpg"; + final String ImagePath= df.format(dateobj) +".jpg"; StorageReference mountainsRef = storageRef.child("images/"+ ImagePath); ivUserImage.setDrawingCacheEnabled(true); ivUserImage.buildDrawingCache(); @@ -157,89 +135,16 @@ public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { } catch (UnsupportedEncodingException e) { } + //TODO: login and register String url="http://10.0.2.2/~hussienalrubaye/twitterserver/register.php?first_name="+name+"&email="+etEmail.getText().toString()+"&password="+etPassword.getText().toString()+"&picture_path="+ downloadUrl; new MyAsyncTaskgetNews().execute(url); + //hideProgressDialog(); } }); } - // get news from server - public class MyAsyncTaskgetNews extends AsyncTask { - @Override - protected void onPreExecute() { - //before works - } - @Override - protected String doInBackground(String... params) { - // TODO Auto-generated method stub - try { - String NewsData; - //define the url we have to connect with - URL url = new URL(params[0]); - //make connect with url and send request - HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); - //waiting for 7000ms for response - urlConnection.setConnectTimeout(7000);//set timeout to 5 seconds - - try { - //getting the response data - InputStream in = new BufferedInputStream(urlConnection.getInputStream()); - //convert the stream to string - Operations operations=new Operations(getApplicationContext()); - NewsData = operations.ConvertInputToStringNoChange(in); - //send to display data - publishProgress(NewsData); - } finally { - //end connection - urlConnection.disconnect(); - } - - }catch (Exception ex){} - return null; - } - protected void onProgressUpdate(String... progress) { - - try { - JSONObject json= new JSONObject(progress[0]); - //display response data - if (json.getString("msg")==null) - return; - if (json.getString("msg").equalsIgnoreCase("user is added")) { - Toast.makeText(getApplicationContext(), json.getString("msg"), Toast.LENGTH_LONG).show(); -//login - String url="http://10.0.2.2/~hussienalrubaye/twitterserver/login.php?email="+etEmail.getText().toString()+"&password="+etPassword.getText().toString() ; - - new MyAsyncTaskgetNews().execute(url); - } - - if (json.getString("msg").equalsIgnoreCase("Pass Login")) { - JSONArray UserInfo=new JSONArray( json.getString("info")); - JSONObject UserCreintal= UserInfo.getJSONObject(0); - //Toast.makeText(getApplicationContext(),UserCreintal.getString("user_id"),Toast.LENGTH_LONG).show(); - hideProgressDialog(); - SaveSettings saveSettings= new SaveSettings(getApplicationContext()); - saveSettings.SaveData(UserCreintal.getString("user_id")); - finish(); //close this activity - } - - } catch (Exception ex) { - Log.d("er", ex.getMessage()); - } - - - } - - protected void onPostExecute(String result2){ - - - } - - - - - } // [START on_start_add_listener] @Override @@ -260,7 +165,7 @@ public void onStop() { hideProgressDialog(); } private void signInAnonymously() { - // [START signin_anonymously] + // [START signin_anonymously] mAuth.signInAnonymously() .addOnCompleteListener(this, new OnCompleteListener() { @Override @@ -281,26 +186,6 @@ public void onComplete(@NonNull Task task) { } - @VisibleForTesting - public ProgressDialog mProgressDialog; - - public void showProgressDialog() { - if (mProgressDialog == null) { - mProgressDialog = new ProgressDialog(this); - mProgressDialog.setMessage("loading"); - mProgressDialog.setIndeterminate(true); - } - - mProgressDialog.show(); - } - - public void hideProgressDialog() { - if (mProgressDialog != null && mProgressDialog.isShowing()) { - mProgressDialog.dismiss(); - } - } - - void CheckUserPermsions(){ if ( Build.VERSION.SDK_INT >= 23){ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != @@ -337,6 +222,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in } } + int RESULT_LOAD_IMAGE=346; void LoadImage(){ Intent i = new Intent( Intent.ACTION_PICK, @@ -344,4 +230,124 @@ void LoadImage(){ startActivityForResult(i, RESULT_LOAD_IMAGE); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { + Uri selectedImage = data.getData(); + String[] filePathColumn = {MediaStore.Images.Media.DATA}; + + Cursor cursor = getContentResolver().query(selectedImage, + filePathColumn, null, null, null); + cursor.moveToFirst(); + + int columnIndex = cursor.getColumnIndex(filePathColumn[0]); + String picturePath = cursor.getString(columnIndex); + cursor.close(); + ivUserImage.setImageBitmap(BitmapFactory.decodeFile(picturePath)); + + } + } + + + + // loading display + + @VisibleForTesting + public ProgressDialog mProgressDialog; + + public void showProgressDialog() { + if (mProgressDialog == null) { + mProgressDialog = new ProgressDialog(this); + mProgressDialog.setMessage("loading"); + mProgressDialog.setIndeterminate(true); + } + + mProgressDialog.show(); + } + + public void hideProgressDialog() { + if (mProgressDialog != null && mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + } + } + + // get news from server + public class MyAsyncTaskgetNews extends AsyncTask { + @Override + protected void onPreExecute() { + //before works + } + @Override + protected String doInBackground(String... params) { + // TODO Auto-generated method stub + try { + String NewsData; + //define the url we have to connect with + URL url = new URL(params[0]); + //make connect with url and send request + HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); + //waiting for 7000ms for response + urlConnection.setConnectTimeout(7000);//set timeout to 5 seconds + + try { + //getting the response data + InputStream in = new BufferedInputStream(urlConnection.getInputStream()); + //convert the stream to string + Operations operations=new Operations(getApplicationContext()); + NewsData = operations.ConvertInputToStringNoChange(in); + //send to display data + publishProgress(NewsData); + } finally { + //end connection + urlConnection.disconnect(); + } + + }catch (Exception ex){} + return null; + } + protected void onProgressUpdate(String... progress) { + + try { + JSONObject json= new JSONObject(progress[0]); + //display response data + if (json.getString("msg")==null) + return; + if (json.getString("msg").equalsIgnoreCase("user is added")) { + Toast.makeText(getApplicationContext(), json.getString("msg"), Toast.LENGTH_LONG).show(); +//login + String url="http://10.0.2.2/~hussienalrubaye/twitterserver/login.php?email="+etEmail.getText().toString()+"&password="+etPassword.getText().toString() ; + + new MyAsyncTaskgetNews().execute(url); + } + + if (json.getString("msg").equalsIgnoreCase("Pass Login")) { + JSONArray UserInfo=new JSONArray( json.getString("info")); + JSONObject UserCreintal= UserInfo.getJSONObject(0); + //Toast.makeText(getApplicationContext(),UserCreintal.getString("user_id"),Toast.LENGTH_LONG).show(); + hideProgressDialog(); + SaveSettings saveSettings= new SaveSettings(getApplicationContext()); + saveSettings.SaveData(UserCreintal.getString("user_id")); + finish(); //close this activity + } + + } catch (Exception ex) { + Log.d("er", ex.getMessage()); + } + + + } + + protected void onPostExecute(String result2){ + + + } + + + + + } + + } diff --git a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/MainActivity.java b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/MainActivity.java old mode 100644 new mode 100755 index b01021be377e..10d7f3c3359e --- a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/MainActivity.java +++ b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/MainActivity.java @@ -40,6 +40,7 @@ import com.google.firebase.storage.UploadTask; import com.squareup.picasso.Picasso; + import org.json.JSONArray; import org.json.JSONObject; @@ -57,12 +58,15 @@ public class MainActivity extends AppCompatActivity { //adapter class ArrayList listnewsData = new ArrayList(); - MyCustomAdapter myadapter; + int StartFrom=0; + int UserOperation=SearchType.MyFollowing; // 0 my followers post 2- specifc user post 3- search post + String Searchquery; int totalItemCountVisible=0; //totalItems visible LinearLayout ChannelInfo; TextView txtnamefollowers; int SelectedUserID=0; Button buFollow; + MyCustomAdapter myadapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -71,47 +75,21 @@ protected void onCreate(Bundle savedInstanceState) { ChannelInfo.setVisibility(View.GONE); txtnamefollowers=(TextView)findViewById(R.id.txtnamefollowers) ; buFollow=(Button)findViewById(R.id.buFollow); - SaveSettings saveSettings= new SaveSettings(getApplicationContext()); - saveSettings.LoadData(); + SaveSettings saveSettings= new SaveSettings(getApplicationContext()); + saveSettings.LoadData(); - //add data and view it - // listnewsData.add(new AdapterItems( null, null,null,"add",null,null ,null)); myadapter=new MyCustomAdapter(this,listnewsData); ListView lsNews=(ListView)findViewById(R.id.LVNews); lsNews.setAdapter(myadapter);//intisal with data LoadTweets(0,SearchType.MyFollowing); - // list view scrool - lsNews.setOnScrollListener(new AbsListView.OnScrollListener() { - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { -// scroll up loading - } - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - //firstVisibleItem it have been seen - //visibleItemCount visible now - totalItemCountVisible=firstVisibleItem + visibleItemCount; - if(totalItemCountVisible== totalItemCount) - { - - if (listnewsData.size()>5) - if (!listnewsData.get(listnewsData.size()-1).tweet_date.equals("loading") - && !listnewsData.get(0).tweet_date.equals("loading")) - LoadTweets(listnewsData.size()-1,UserOperation); - - } - - - } - }); - } public void buFollowers(View view) { +//TODO: add code s=for subscribe and un subscribe + int Operation; // 1- subsribe 2- unsubscribe String Follow=buFollow.getText().toString(); @@ -124,15 +102,66 @@ public void buFollowers(View view) { buFollow.setText("Follow"); } - String url="http://10.0.2.2/~hussienalrubaye/twitterserver/userfollowing.php?user_id="+SaveSettings.UserID +"&following_user_id="+SelectedUserID+"&op="+ Operation; + String url="http://10.0.2.2/~hussienalrubaye/twitterserver/userfollowing.php?user_id="+SaveSettings.UserID +"&following_user_id="+SelectedUserID+"&op="+ Operation; new MyAsyncTaskgetNews().execute(url); + } + + SearchView searchView; + Menu myMenu; + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + myMenu=menu; + // Associate searchable configuration with the SearchView + SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); + searchView = (android.widget.SearchView) menu.findItem(R.id.searchbar).getActionView(); + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + //final Context co=this; + searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + // Toast.makeText(co, query, Toast.LENGTH_LONG).show(); + Searchquery=null; + try { + //for space with name + Searchquery = java.net.URLEncoder.encode(query , "UTF-8"); + } catch (UnsupportedEncodingException e) { + + } + //TODO: search in posts + LoadTweets(0,SearchType.SearchIn);// seearch + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + return false; + } + }); + // searchView.setOnCloseListener(this); + return true; + } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle item selection + switch (item.getItemId()) { + case R.id.home: + //TODO: main search + LoadTweets(0,SearchType.MyFollowing); + return true; + + default: + return super.onOptionsItemSelected(item); + } } + private class MyCustomAdapter extends BaseAdapter { public ArrayList listnewsDataAdpater ; -Context context; + Context context; public MyCustomAdapter(Context context,ArrayList listnewsDataAdpater) { this.listnewsDataAdpater=listnewsDataAdpater; this.context=context; @@ -164,7 +193,7 @@ public View getView(int position, View convertView, ViewGroup parent) LayoutInflater mInflater = getLayoutInflater(); View myView = mInflater.inflate(R.layout.tweet_add, null); - final EditText etPost = (EditText) myView.findViewById(R.id.etPost); + final EditText etPost = (EditText) myView.findViewById(R.id.etPost); ImageView iv_post=(ImageView) myView.findViewById(R.id.iv_post) ; @@ -172,12 +201,13 @@ public View getView(int position, View convertView, ViewGroup parent) iv_attach.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - LoadImage(); + LoadImage(); } }); iv_post.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + String tweets=null; try { //for space with name @@ -216,12 +246,14 @@ else if(s.tweet_date.equals("notweet")) { txtUserName.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + SelectedUserID=Integer.parseInt(s.user_id); LoadTweets(0,SearchType.OnePerson); txtnamefollowers.setText(s.first_name); - SelectedUserID=Integer.parseInt(s.user_id); + String url="http://10.0.2.2/~hussienalrubaye/twitterserver/isfollowing.php?user_id="+SaveSettings.UserID +"&following_user_id="+SelectedUserID; new MyAsyncTaskgetNews().execute(url); + } }); TextView txt_tweet = (TextView) myView.findViewById(R.id.txt_tweet); @@ -231,16 +263,107 @@ public void onClick(View view) { txt_tweet_date.setText(s.tweet_date); ImageView tweet_picture=(ImageView)myView.findViewById(R.id.tweet_picture); - Picasso.with(context).load(s.tweet_picture).into(tweet_picture); + Picasso.with(context).load(s.tweet_picture).into(tweet_picture); ImageView picture_path=(ImageView)myView.findViewById(R.id.picture_path); - Picasso.with(context).load(s.picture_path).into(picture_path); + Picasso.with(context).load(s.picture_path).into(picture_path); return myView; } } + + //load image } + //load image + //pop + + @VisibleForTesting + public ProgressDialog mProgressDialog; + + public void showProgressDialog() { + if (mProgressDialog == null) { + mProgressDialog = new ProgressDialog(this); + mProgressDialog.setMessage("loading"); + mProgressDialog.setIndeterminate(true); + } + + mProgressDialog.show(); + } + + public void hideProgressDialog() { + if (mProgressDialog != null && mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + } + } + + + //save image + int RESULT_LOAD_IMAGE=233; + void LoadImage(){ + Intent i = new Intent( + Intent.ACTION_PICK, + android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + + startActivityForResult(i, RESULT_LOAD_IMAGE); + } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { + Uri selectedImage = data.getData(); + String[] filePathColumn = {MediaStore.Images.Media.DATA}; + + Cursor cursor = getContentResolver().query(selectedImage, + filePathColumn, null, null, null); + cursor.moveToFirst(); + + int columnIndex = cursor.getColumnIndex(filePathColumn[0]); + String picturePath = cursor.getString(columnIndex); + cursor.close(); + // postImage.setImageBitmap(BitmapFactory.decodeFile(picturePath)); + uploadimage( BitmapFactory.decodeFile(picturePath)); + } + } + String downloadUrl=null; + // ImageView postImage = new ImageView(this); + public void uploadimage(Bitmap bitmap ) { + showProgressDialog(); + FirebaseStorage storage=FirebaseStorage.getInstance(); + // Create a storage reference from our app + StorageReference storageRef = storage.getReferenceFromUrl("gs://twitter-app-f69e8.appspot.com"); + DateFormat df = new SimpleDateFormat("ddMMyyHHmmss"); + Date dateobj = new Date(); + // System.out.println(df.format(dateobj)); +// Create a reference to "mountains.jpg" + String mydownloadUrl=SaveSettings.UserID+ "_"+ df.format(dateobj) +".jpg"; + StorageReference mountainsRef = storageRef.child("images/"+ mydownloadUrl); + // postImage.setDrawingCacheEnabled(true); + // postImage.buildDrawingCache(); + // Bitmap bitmap = imageView.getDrawingCache(); + // BitmapDrawable drawable=(BitmapDrawable)postImage.getDrawable(); + // Bitmap bitmap =drawable.getBitmap(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); + byte[] data = baos.toByteArray(); + + UploadTask uploadTask = mountainsRef.putBytes(data); + uploadTask.addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception exception) { + // Handle unsuccessful uploads + } + }).addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL. + downloadUrl = taskSnapshot.getDownloadUrl().toString(); + hideProgressDialog(); + } + }); + } + // get news from server public class MyAsyncTaskgetNews extends AsyncTask { @Override @@ -285,7 +408,7 @@ protected void onProgressUpdate(String... progress) { return; if (json.getString("msg").equalsIgnoreCase("tweet is added")) { - LoadTweets(1,UserOperation); + LoadTweets(0,UserOperation); } else if (json.getString("msg").equalsIgnoreCase("has tweet")) { if(StartFrom==0) { @@ -308,7 +431,7 @@ else if (json.getString("msg").equalsIgnoreCase("has tweet")) { listnewsData.add(new AdapterItems(js.getString("tweet_id"), js.getString("tweet_text"),js.getString("tweet_picture") , js.getString("tweet_date") ,js.getString("user_id") ,js.getString("first_name") - ,js.getString("picture_path") )); + ,js.getString("picture_path") )); } @@ -316,7 +439,7 @@ else if (json.getString("msg").equalsIgnoreCase("has tweet")) { } - else if (json.getString("msg").equalsIgnoreCase("no tweet")) { + else if (json.getString("msg").equalsIgnoreCase("no tweet")) { //remove we are loading now if(StartFrom==0) { listnewsData.clear(); @@ -327,7 +450,7 @@ else if (json.getString("msg").equalsIgnoreCase("no tweet")) { //remove we are loading now listnewsData.remove(listnewsData.size()-1); } - // listnewsData.remove(listnewsData.size()-1); + // listnewsData.remove(listnewsData.size()-1); listnewsData.add(new AdapterItems(null, null, null, "notweet", null, null, null)); } @@ -360,160 +483,14 @@ protected void onPostExecute(String result2){ } - SearchView searchView; - Menu myMenu; - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.menu_main, menu); - myMenu=menu; - // Associate searchable configuration with the SearchView - SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); - searchView = (android.widget.SearchView) menu.findItem(R.id.searchbar).getActionView(); - searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); - //final Context co=this; - searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - // Toast.makeText(co, query, Toast.LENGTH_LONG).show(); - Searchquery=null; - try { - //for space with name - Searchquery = java.net.URLEncoder.encode(query , "UTF-8"); - } catch (UnsupportedEncodingException e) { - - } - LoadTweets(0,SearchType.SearchIn);// seearch - return false; - } - - @Override - public boolean onQueryTextChange(String newText) { - return false; - } - }); - // searchView.setOnCloseListener(this); - return true; - } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle item selection - switch (item.getItemId()) { - case R.id.home: - LoadTweets(0,SearchType.MyFollowing); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - //pop - - @VisibleForTesting - public ProgressDialog mProgressDialog; - - public void showProgressDialog() { - if (mProgressDialog == null) { - mProgressDialog = new ProgressDialog(this); - mProgressDialog.setMessage("loading"); - mProgressDialog.setIndeterminate(true); - } - - mProgressDialog.show(); - } - - public void hideProgressDialog() { - if (mProgressDialog != null && mProgressDialog.isShowing()) { - mProgressDialog.dismiss(); - } - } - - - //save image - int RESULT_LOAD_IMAGE=233; - void LoadImage(){ - Intent i = new Intent( - Intent.ACTION_PICK, - android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - - startActivityForResult(i, RESULT_LOAD_IMAGE); - } - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { - Uri selectedImage = data.getData(); - String[] filePathColumn = {MediaStore.Images.Media.DATA}; - - Cursor cursor = getContentResolver().query(selectedImage, - filePathColumn, null, null, null); - cursor.moveToFirst(); - - int columnIndex = cursor.getColumnIndex(filePathColumn[0]); - String picturePath = cursor.getString(columnIndex); - cursor.close(); - // postImage.setImageBitmap(BitmapFactory.decodeFile(picturePath)); - uploadimage( BitmapFactory.decodeFile(picturePath)); - } - } - String downloadUrl=null; - // ImageView postImage = new ImageView(this); - public void uploadimage(Bitmap bitmap ) { - showProgressDialog(); - FirebaseStorage storage=FirebaseStorage.getInstance(); - // Create a storage reference from our app - StorageReference storageRef = storage.getReferenceFromUrl("gs://firbasedemo-6228f.appspot.com"); - DateFormat df = new SimpleDateFormat("ddMMyyHHmmss"); - Date dateobj = new Date(); - // System.out.println(df.format(dateobj)); -// Create a reference to "mountains.jpg" - String mydownloadUrl=SaveSettings.UserID+ "_"+ df.format(dateobj) +".jpg"; - StorageReference mountainsRef = storageRef.child("images/"+ mydownloadUrl); - // postImage.setDrawingCacheEnabled(true); - // postImage.buildDrawingCache(); - // Bitmap bitmap = imageView.getDrawingCache(); - // BitmapDrawable drawable=(BitmapDrawable)postImage.getDrawable(); - // Bitmap bitmap =drawable.getBitmap(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); - byte[] data = baos.toByteArray(); - - UploadTask uploadTask = mountainsRef.putBytes(data); - uploadTask.addOnFailureListener(new OnFailureListener() { - @Override - public void onFailure(@NonNull Exception exception) { - // Handle unsuccessful uploads - } - }).addOnSuccessListener(new OnSuccessListener() { - @Override - public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { - // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL. - downloadUrl = taskSnapshot.getDownloadUrl().toString(); - hideProgressDialog(); - } - }); - } - - - - - protected void onResume(){ - super.onResume(); - // LoadTweets(); - } - int StartFrom=0; - int UserOperation=SearchType.MyFollowing; // 0 my followers post 2- specifc user post 3- search post - String Searchquery; void LoadTweets(int StartFrom,int UserOperation){ this.StartFrom=StartFrom; this.UserOperation=UserOperation; //display loading if(StartFrom==0) // add loading at beggining - listnewsData.add(0,new AdapterItems(null, null, null, - "loading", null, null, null)); - else // add loading at end + listnewsData.add(0,new AdapterItems(null, null, null, + "loading", null, null, null)); + else // add loading at end listnewsData.add(new AdapterItems(null, null, null, "loading", null, null, null)); @@ -521,8 +498,10 @@ void LoadTweets(int StartFrom,int UserOperation){ String url="http://10.0.2.2/~hussienalrubaye/twitterserver/tweetlist.php?user_id="+ SaveSettings.UserID + "&StartFrom="+StartFrom + "&op="+ UserOperation; - if (UserOperation==3) - url="http://10.0.2.2/~hussienalrubaye/twitterserver/tweetlist.php?user_id="+ SaveSettings.UserID + "&StartFrom="+StartFrom + "&op="+ UserOperation + "&query="+ Searchquery; + if (UserOperation==SearchType.SearchIn) + url="http://10.0.2.2/~hussienalrubaye/twitterserver/tweetlist.php?user_id="+ SaveSettings.UserID + "&StartFrom="+StartFrom + "&op="+ UserOperation + "&query="+ Searchquery; + if(UserOperation==SearchType.OnePerson) + url="http://10.0.2.2/~hussienalrubaye/twitterserver/tweetlist.php?user_id="+ SelectedUserID + "&StartFrom="+StartFrom + "&op="+ UserOperation; new MyAsyncTaskgetNews().execute(url); @@ -534,4 +513,5 @@ void LoadTweets(int StartFrom,int UserOperation){ } + } diff --git a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/Operations.java b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/Operations.java old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/SaveSettings.java b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/SaveSettings.java old mode 100644 new mode 100755 index 3544ed2b970a..9a95a55f6358 --- a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/SaveSettings.java +++ b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/SaveSettings.java @@ -10,9 +10,6 @@ public class SaveSettings { public static String UserID=""; - //https://firebasestorage.googleapis.com/v0/b/firbasedemo-6228f.appspot.com/o/images%2F32_131116124812.jpg?alt=media&token=0287e868-557b-431c-bccc-7245d5fe8fc6 - public static String ServerImages=""; - Context context; SharedPreferences ShredRef; @@ -25,7 +22,9 @@ void SaveData(String UserID){ SharedPreferences.Editor editor=ShredRef.edit(); editor.putString("UserID",UserID); + editor.commit(); + LoadData(); } void LoadData(){ diff --git a/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/SearchType.java b/TwitterApp/TwitterDem/app/src/main/java/com/alrubaye/twitterdem/SearchType.java old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/add.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/add.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/background.xml b/TwitterApp/TwitterDem/app/src/main/res/drawable/background.xml old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/barcolor.xml b/TwitterApp/TwitterDem/app/src/main/res/drawable/barcolor.xml old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_account_circle_black_24dp.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_account_circle_black_24dp.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_attach_file_black_24dp.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_attach_file_black_24dp.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_favorite_border_black_24dp.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_favorite_border_black_24dp.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_home_black_24dp.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_home_black_24dp.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_home_white_24dp.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_home_white_24dp.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_send_black_24dp.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/ic_send_black_24dp.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/persoicon.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/persoicon.png new file mode 100644 index 000000000000..10b9a5aa08ad Binary files /dev/null and b/TwitterApp/TwitterDem/app/src/main/res/drawable/persoicon.png differ diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/tweets.png b/TwitterApp/TwitterDem/app/src/main/res/drawable/tweets.png old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/drawable/twitter.jpg b/TwitterApp/TwitterDem/app/src/main/res/drawable/twitter.jpg old mode 100644 new mode 100755 diff --git a/TwitterApp/TwitterDem/app/src/main/res/layout-hdpi/tweet_item.xml b/TwitterApp/TwitterDem/app/src/main/res/layout-hdpi/tweet_item.xml new file mode 100644 index 000000000000..0222313cf010 --- /dev/null +++ b/TwitterApp/TwitterDem/app/src/main/res/layout-hdpi/tweet_item.xml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TwitterApp/TwitterDem/app/src/main/res/layout-xhdpi/tweet_item.xml b/TwitterApp/TwitterDem/app/src/main/res/layout-xhdpi/tweet_item.xml new file mode 100644 index 000000000000..52b11c60a282 --- /dev/null +++ b/TwitterApp/TwitterDem/app/src/main/res/layout-xhdpi/tweet_item.xml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TwitterApp/TwitterDem/app/src/main/res/layout-xxhdpi/tweet_item.xml b/TwitterApp/TwitterDem/app/src/main/res/layout-xxhdpi/tweet_item.xml new file mode 100644 index 000000000000..ed77202c086b --- /dev/null +++ b/TwitterApp/TwitterDem/app/src/main/res/layout-xxhdpi/tweet_item.xml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TwitterApp/TwitterDem/app/src/main/res/layout-xxxhdpi/tweet_item.xml b/TwitterApp/TwitterDem/app/src/main/res/layout-xxxhdpi/tweet_item.xml new file mode 100644 index 000000000000..bc8150eb473c --- /dev/null +++ b/TwitterApp/TwitterDem/app/src/main/res/layout-xxxhdpi/tweet_item.xml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TwitterApp/TwitterDem/app/src/main/res/layout/activity_login.xml b/TwitterApp/TwitterDem/app/src/main/res/layout/activity_login.xml old mode 100644 new mode 100755 index e9c3a5d6712d..531aef12c17d --- a/TwitterApp/TwitterDem/app/src/main/res/layout/activity_login.xml +++ b/TwitterApp/TwitterDem/app/src/main/res/layout/activity_login.xml @@ -26,6 +26,7 @@ android:id="@+id/etName" /> + android:layout_marginBottom="1dp" + android:layout_height="100pt" + android:layout_width="80pt" />