Skip to content

Commit

Permalink
Few Tweaks
Browse files Browse the repository at this point in the history
-Narrowed location search to India
-Messages loading progress dialog added
-An easter egg!!
  • Loading branch information
divya21raj committed Mar 30, 2018
1 parent 95235ef commit 45e6d04
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ protected void onStart()
public void onPause()
{
super.onPause();

overridePendingTransition(0, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
Expand All @@ -12,7 +14,12 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.TaskCompletionSource;

import garbagecollectors.com.unipool.R;
import garbagecollectors.com.unipool.adapters.HomeActivityTEA;
Expand All @@ -24,7 +31,7 @@ public class HomeActivity extends BaseActivity

static public RelativeLayout noEntryRelativeLayout;

@Override
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Expand All @@ -42,6 +49,11 @@ protected void onCreate(Bundle savedInstanceState)
drawerLayout = findViewById(R.id.home_layout);

noEntryRelativeLayout = findViewById(R.id.no_entry_message);
noEntryRelativeLayout.setOnLongClickListener(v ->
{
changeToSOLogo();
return true;
});

navDrawerStateListener();

Expand Down Expand Up @@ -74,6 +86,30 @@ protected void onCreate(Bundle savedInstanceState)

}

private void changeToSOLogo()
{
TaskCompletionSource<Void> timerSource = new TaskCompletionSource<>();
Task<Void> timerTask = timerSource.getTask();

Handler handler = new Handler();
handler.postDelayed(() -> timerSource.setResult(null), 3350);

ImageView mainImage = noEntryRelativeLayout.findViewById(R.id.sad_smiley);
TextView header = noEntryRelativeLayout.findViewById(R.id.such_empty);
TextView footer = noEntryRelativeLayout.findViewById(R.id.no_entry_description);

mainImage.setBackground(ContextCompat.getDrawable(HomeActivity.this, R.drawable.ic_so_icon));
header.setText("Is Bae");
footer.setText("");

timerTask.addOnCompleteListener(task ->
{
mainImage.setBackground(ContextCompat.getDrawable(HomeActivity.this, R.drawable.ic_negative_smiley));
header.setText("Such empty...");
footer.setText("Maybe you can create a new entry?");
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package garbagecollectors.com.unipool.activities;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
Expand Down Expand Up @@ -39,7 +40,9 @@ public class MessageListActivity extends AppCompatActivity
EditText messageArea;
ScrollView scrollView;

private static TreeMap<Long, Message> personalMessageMap; //key = CreatedItTime
ProgressDialog messageProgressDialog;

private static TreeMap<Long, Message> personalMessageMap; //key = CreatedAtTime
private static User chatUser;

private static PairUp pairUp;
Expand All @@ -62,11 +65,17 @@ protected void onCreate(Bundle savedInstanceState)

messagesOnScreen = new ArrayList<>();

messageProgressDialog = new ProgressDialog(this);
messageProgressDialog.setMessage("Fetching your messages...");
messageProgressDialog.show();

setScrollViewToBottom();

DatabaseReference userMessageDatabaseReference = FirebaseDatabase.getInstance().
getReference("messages/" + BaseActivity.getFinalCurrentUser().getUserId());

//load from local

userMessageDatabaseReference.addChildEventListener(new ChildEventListener()
{
@Override
Expand All @@ -76,7 +85,6 @@ public void onChildAdded(DataSnapshot dataSnapshot, String s)

if (message != null)
{
messageArea.setHint("Fetching messages....");
UtilityMethods.putMessageInMap(BaseActivity.getMessages(), message);

if (!message.getMessageId().equals("def@ult") && (message.getSenderId().equals(chatUser.getUserId())
Expand All @@ -89,9 +97,11 @@ public void onChildAdded(DataSnapshot dataSnapshot, String s)
showMessage(message);
}
}

else if(message.getMessageId().equals("def@ult"))
messageProgressDialog.dismiss();
}

messageArea.setHint("Write a message...");
}

@Override
Expand Down Expand Up @@ -167,21 +177,12 @@ public void onBackPressed()
setName("asdsafasde");
}

private void setScrollViewToBottom()
{
View lastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
int bottom = lastChild.getBottom() + scrollView.getPaddingBottom();
int sy = scrollView.getScrollY();
int sh = scrollView.getHeight();
int delta = bottom - (sy + sh);

scrollView.smoothScrollBy(0, delta);
}

private void showMessage(Message message)
{
messagesOnScreen.add(message.getMessageId());

//messageProgressDialog.dismiss();

if(message.getSenderId().equals(BaseActivity.getFinalCurrentUser().getUserId()))
{
addMessageBox(message.getMessage(), message.getCreatedAtTime(), 1);
Expand Down Expand Up @@ -230,6 +231,17 @@ public void addMessageBox(String message, Long createdAtTime, int type)
setScrollViewToBottom();
}

private void setScrollViewToBottom()
{
View lastChild = scrollView.getChildAt(scrollView.getChildCount() - 1);
int bottom = lastChild.getBottom() + scrollView.getPaddingBottom();
int sy = scrollView.getScrollY();
int sh = scrollView.getHeight();
int delta = bottom - (sy + sh);

scrollView.smoothScrollBy(0, delta);
}



public static void setPairUp(PairUp pairUp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.Place;
import com.google.android.gms.location.places.PlaceLikelihood;
import com.google.android.gms.location.places.PlaceLikelihoodBuffer;
Expand Down Expand Up @@ -203,8 +204,14 @@ private void showPlaceAutocomplete(int i)
{
try
{
AutocompleteFilter autocompleteFilter = new AutocompleteFilter.Builder()
.setTypeFilter(Place.TYPE_COUNTRY)
.setCountry("IN")
.build();

Intent intent =
new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
.setFilter(autocompleteFilter)
.build(this);
startActivityForResult(intent, i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class SplashActivity extends AppCompatActivity
FirebaseAuth mAuth;
static FirebaseUser currentUser;

private TaskCompletionSource<Void> delaySource = new TaskCompletionSource<>();
private Task<Void> delayTask = delaySource.getTask();
private TaskCompletionSource<Void> timerSource = new TaskCompletionSource<>();
private Task<Void> timerTask = timerSource.getTask();

private TaskCompletionSource<DataSnapshot> UserDBSource = new TaskCompletionSource<>();
private Task UserDBTask = UserDBSource.getTask();
Expand Down Expand Up @@ -72,7 +72,8 @@ protected void onCreate(Bundle savedInstanceState)

messageDatabaseReference = FirebaseDatabase.getInstance().getReference("messages/" + currentUser.getUid());

new Handler().postDelayed(() -> delaySource.setResult(null), 2350);
Handler handler = new Handler();
handler.postDelayed(() -> timerSource.setResult(null), 12350);

userDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener()
{
Expand Down Expand Up @@ -106,9 +107,11 @@ public void onCancelled(DatabaseError databaseError)
}
});

Task<Void> allTask = Tasks.whenAll(UserDBTask, EntryDBTask, delayTask);
Task<Void> allTask = Tasks.whenAll(UserDBTask, EntryDBTask);
allTask.addOnSuccessListener(aVoid ->
{
handler.removeCallbacksAndMessages(null);

DataSnapshot userData = (DataSnapshot) UserDBTask.getResult();
DataSnapshot entryData = (DataSnapshot) EntryDBTask.getResult();

Expand Down Expand Up @@ -155,6 +158,12 @@ public void onCancelled(DatabaseError databaseError)
// apologize profusely to the user!
Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
});

timerTask.addOnCompleteListener(task ->
{
if(timerTask.getResult() == null)
Toast.makeText(this, "Network not that good, I'm trying...", Toast.LENGTH_LONG).show();
});
}

public static ArrayList<TripEntry> getTripEntryList()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_so_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:viewportHeight="120.0"
android:viewportWidth="120.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#BCBBBB" android:pathData="M84.4,93.8l0,-23.2l7.7,0l0,30.9l-69.5,0l0,-30.9l7.7,0l0,23.2z"/>
<path android:fillColor="#F48023" android:pathData="M38.8,68.4l37.8,7.9l1.6,-7.6l-37.8,-7.9L38.8,68.4zM43.8,50.4l35,16.3l3.2,-7l-35,-16.4L43.8,50.4zM53.5,33.2l29.7,24.7l4.9,-5.9L58.4,27.3L53.5,33.2zM72.7,14.9l-6.2,4.6l23,31l6.2,-4.6L72.7,14.9zM38,86h38.6v-7.7H38V86z"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/no_entry_description"
android:paddingTop="8dp"
android:textSize="14sp"
android:layout_centerHorizontal="true"
Expand Down

0 comments on commit 45e6d04

Please sign in to comment.