Search in sources :

Example 1 with FirebaseRemoteConfigSettings

use of com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings in project quickstart-android by firebase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWelcomeTextView = (TextView) findViewById(R.id.welcomeTextView);
    Button fetchButton = (Button) findViewById(R.id.fetchButton);
    fetchButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            fetchWelcome();
        }
    });
    // Get Remote Config instance.
    // [START get_remote_config_instance]
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    // [END get_remote_config_instance]
    // Create a Remote Config Setting to enable developer mode, which you can use to increase
    // the number of fetches available per hour during development. See Best Practices in the
    // README for more information.
    // [START enable_dev_mode]
    FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(BuildConfig.DEBUG).build();
    mFirebaseRemoteConfig.setConfigSettings(configSettings);
    // [END enable_dev_mode]
    // Set default Remote Config parameter values. An app uses the in-app default values, and
    // when you need to adjust those defaults, you set an updated value for only the values you
    // want to change in the Firebase console. See Best Practices in the README for more
    // information.
    // [START set_default_values]
    mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
    // [END set_default_values]
    fetchWelcome();
}
Also used : Button(android.widget.Button) TextView(android.widget.TextView) View(android.view.View) FirebaseRemoteConfigSettings(com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings)

Example 2 with FirebaseRemoteConfigSettings

use of com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings in project RSAndroidApp by RailwayStations.

the class AuthActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auth);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    subscribtionStatus();
    mUsername = ANONYMOUS;
    // Initialize Firebase Auth
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();
    ChatMessage friendly_chat = new ChatMessage();
    mTimeStamp = friendly_chat.setChatTimeStamp();
    if (mFirebaseUser == null) {
        // Not signed in, launch the Sign In activity
        startActivity(new Intent(this, SignInActivity.class));
        finish();
        return;
    } else {
        mUsername = mFirebaseUser.getDisplayName();
        mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
    }
    mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
    this).addApi(Auth.GOOGLE_SIGN_IN_API).build();
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setStackFromEnd(true);
    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAdapter = new FirebaseRecyclerAdapter<ChatMessage, MessageViewHolder>(ChatMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) {

        @Override
        protected void populateViewHolder(MessageViewHolder viewHolder, ChatMessage friendlyMessage, int position) {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            viewHolder.messageTextView.setText(friendlyMessage.getText());
            viewHolder.messengerTextView.setText(friendlyMessage.getName());
            viewHolder.messengerTimeStamp.setText(friendlyMessage.getChatTimeStamp());
            if (friendlyMessage.getPhotoUrl() == null) {
                viewHolder.messengerImageView.setImageDrawable(ContextCompat.getDrawable(AuthActivity.this, R.drawable.ic_account_circle_black_36dp));
            } else {
                Glide.with(AuthActivity.this).load(friendlyMessage.getPhotoUrl()).into(viewHolder.messengerImageView);
            }
        }
    };
    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            int friendlyMessageCount = mFirebaseAdapter.getItemCount();
            int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
            // to the bottom of the list to show the newly added message.
            if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) {
                mMessageRecyclerView.scrollToPosition(positionStart);
            }
        }
    });
    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
    mMessageRecyclerView.setAdapter(mFirebaseAdapter);
    // Initialize Firebase Remote Config.
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    // Define Firebase Remote Config Settings.
    FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build();
    // Define default config values. Defaults are used when fetched config values are not
    // available. Eg: if an error occurred fetching values from the server.
    Map<String, Object> defaultConfigMap = new HashMap<>();
    defaultConfigMap.put("friendly_msg_length", 10L);
    // Apply config settings and default values.
    mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings);
    mFirebaseRemoteConfig.setDefaults(defaultConfigMap);
    // Fetch remote config.
    fetchConfig();
    mMessageEditText = (EditText) findViewById(R.id.messageEditText);
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mSharedPreferences.getInt(FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) });
    mMessageEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.toString().trim().length() > 0) {
                mSendButton.setEnabled(true);
            } else {
                mSendButton.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    mSendButton = (Button) findViewById(R.id.sendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl, mTimeStamp);
            mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(chatMessage);
            mMessageEditText.setText("");
        }
    });
}
Also used : InputFilter(android.text.InputFilter) ChatMessage(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ChatMessage) HashMap(java.util.HashMap) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) FirebaseRemoteConfigSettings(com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 FirebaseRemoteConfigSettings (com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings)2 Intent (android.content.Intent)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Editable (android.text.Editable)1 InputFilter (android.text.InputFilter)1 TextWatcher (android.text.TextWatcher)1 Button (android.widget.Button)1 ChatMessage (de.bahnhoefe.deutschlands.bahnhofsfotos.model.ChatMessage)1 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)1 HashMap (java.util.HashMap)1