Search in sources :

Example 1 with Logo

use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.

the class AccountBookTagViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
                bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                    @Override
                    public void onSuccess(List<Logo> object) {
                        // there has been an old logo in the server/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                            @Override
                            public void onCompleted(Exception e, File file) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 2 with Logo

use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.

the class AccountBookTodayViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                Log.d("CoCoin", user.getLogoObjectId());
                bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
                bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                    @Override
                    public void onSuccess(List<Logo> object) {
                        // there has been an old logo in the server/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                            @Override
                            public void onCompleted(Exception e, File file) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) BmobFile(cn.bmob.v3.datatype.BmobFile) BmobProFile(com.bmob.BmobProFile) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 3 with Logo

use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.

the class AccountBookSettingActivity method uploadLogoToServer.

// update a logo to server//////////////////////////////////////////////////////////////////////////
private void uploadLogoToServer() {
    if (!SettingManager.getInstance().getHasLogo()) {
        // the user haven't set the logo
        return;
    }
    final File file = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
    final User user = getCurrentUser();
    // if login/////////////////////////////////////////////////////////////////////////////////////////
    if (user != null) {
        if (user.getLogoObjectId() != "") {
            // if the logo id is not null, then there must be a logo and a logo file in the server//////////////
            // judge whether there is an old logo of the same user//////////////////////////////////////////////
            BmobQuery<Logo> bmobQuery = new BmobQuery();
            bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
            bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                @Override
                public void onSuccess(List<Logo> object) {
                    // there has been an old logo in the server/////////////////////////////////////////////////////////
                    // then there must be an old logo file in server////////////////////////////////////////////////////
                    // then we should delete the old one////////////////////////////////////////////////////////////////
                    Log.d("Saver", "There is an old logo");
                    String url = object.get(0).getFile().getUrl();
                    BmobFile oldLogoFile = new BmobFile();
                    oldLogoFile.setUrl(url);
                    oldLogoFile.delete(CoCoinApplication.getAppContext(), new DeleteListener() {

                        @Override
                        public void onSuccess() {
                            Log.d("Saver", "Successfully delete the old logo.");
                            // after delete, we should upload a new logo file///////////////////////////////////////////////////
                            final BmobFile newLogoFile = new BmobFile(file);
                            newLogoFile.uploadblock(CoCoinApplication.getAppContext(), new UploadFileListener() {

                                @Override
                                public void onSuccess() {
                                    // after upload the new logo file, we should put the new logo the Logo table////////////////////////
                                    Logo newLogo = new Logo(newLogoFile);
                                    newLogo.update(CoCoinApplication.getAppContext(), user.getLogoObjectId(), new UpdateListener() {

                                        @Override
                                        public void onSuccess() {
                                            Log.d("Saver", "Update logo successfully");
                                        }

                                        @Override
                                        public void onFailure(int arg0, String arg1) {
                                            Log.d("Saver", "Update logo failed " + arg1);
                                        }
                                    });
                                }

                                @Override
                                public void onProgress(Integer arg0) {
                                }

                                @Override
                                public void onFailure(int arg0, String arg1) {
                                    Log.d("Saver", "Upload failed " + arg1);
                                }
                            });
                        }

                        @Override
                        public void onFailure(int code, String msg) {
                            Log.d("Saver", "Fail to delete the old logo. " + msg);
                        }
                    });
                }

                @Override
                public void onError(int code, String msg) {
                    // the picture is lost
                    Log.d("Saver", "Can't find the old logo in server.");
                }
            });
        } else {
            // the user has no logo before//////////////////////////////////////////////////////////////////////
            final BmobFile newLogoFile = new BmobFile(file);
            newLogoFile.uploadblock(CoCoinApplication.getAppContext(), new UploadFileListener() {

                @Override
                public void onSuccess() {
                    String url = newLogoFile.getFileUrl(CoCoinApplication.getAppContext());
                    Log.d("Saver", "Upload successfully " + url);
                    final Logo newLogo = new Logo(newLogoFile);
                    newLogo.save(CoCoinApplication.getAppContext(), new SaveListener() {

                        @Override
                        public void onSuccess() {
                            Log.d("Saver", "Save the new logo successfully.");
                            SettingManager.getInstance().setLogoObjectId(newLogo.getObjectId());
                            updateSettingsToServer(UPDATE_LOGO_ID);
                        }

                        @Override
                        public void onFailure(int i, String s) {
                            Log.d("Saver", "Save the new logo fail.");
                        }
                    });
                }

                @Override
                public void onProgress(Integer arg0) {
                }

                @Override
                public void onFailure(int arg0, String arg1) {
                    Log.d("Saver", "Upload failed " + arg1);
                }
            });
        }
    }
}
Also used : SaveListener(cn.bmob.v3.listener.SaveListener) BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) UploadFileListener(cn.bmob.v3.listener.UploadFileListener) Logo(com.nightonke.saver.model.Logo) BmobQuery(cn.bmob.v3.BmobQuery) DeleteListener(cn.bmob.v3.listener.DeleteListener) UpdateListener(cn.bmob.v3.listener.UpdateListener) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) BmobFile(cn.bmob.v3.datatype.BmobFile)

Example 4 with Logo

use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.

the class AccountBookSettingActivity method loadLogo.

// Load logo from local/////////////////////////////////////////////////////////////////////////////
private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
                bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                    @Override
                    public void onSuccess(List<Logo> object) {
                        // there has been an old logo in the server/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                            @Override
                            public void onCompleted(Exception e, File file) {
                                logo.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                logo.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        logo.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) BmobFile(cn.bmob.v3.datatype.BmobFile) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Example 5 with Logo

use of com.nightonke.saver.model.Logo in project CoCoin by Nightonke.

the class AccountBookListViewActivity method loadLogo.

private void loadLogo() {
    User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
    if (user != null) {
        try {
            File logoFile = new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME);
            if (!logoFile.exists()) {
                // the local logo file is missed
                // try to get from the server
                BmobQuery<Logo> bmobQuery = new BmobQuery();
                bmobQuery.addWhereEqualTo("objectId", user.getLogoObjectId());
                bmobQuery.findObjects(CoCoinApplication.getAppContext(), new FindListener<Logo>() {

                    @Override
                    public void onSuccess(List<Logo> object) {
                        // there has been an old logo in the server/////////////////////////////////////////////////////////
                        String url = object.get(0).getFile().getFileUrl(CoCoinApplication.getAppContext());
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Logo in server: " + url);
                        Ion.with(CoCoinApplication.getAppContext()).load(url).write(new File(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME)).setCallback(new FutureCallback<File>() {

                            @Override
                            public void onCompleted(Exception e, File file) {
                                profileImage.setImageBitmap(BitmapFactory.decodeFile(CoCoinApplication.getAppContext().getFilesDir() + CoCoinUtil.LOGO_NAME));
                            }
                        });
                    }

                    @Override
                    public void onError(int code, String msg) {
                        // the picture is lost
                        if (BuildConfig.DEBUG)
                            Log.d("CoCoin", "Can't find the old logo in server.");
                    }
                });
            } else {
                // the user logo is in the storage
                Bitmap b = BitmapFactory.decodeStream(new FileInputStream(logoFile));
                profileImage.setImageBitmap(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    } else {
        // use the default logo
        profileImage.setImageResource(R.drawable.default_user_logo);
    }
}
Also used : BmobUser(cn.bmob.v3.BmobUser) User(com.nightonke.saver.model.User) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Logo(com.nightonke.saver.model.Logo) Bitmap(android.graphics.Bitmap) BmobQuery(cn.bmob.v3.BmobQuery) File(java.io.File) FutureCallback(com.koushikdutta.async.future.FutureCallback)

Aggregations

BmobQuery (cn.bmob.v3.BmobQuery)7 BmobUser (cn.bmob.v3.BmobUser)7 Logo (com.nightonke.saver.model.Logo)7 User (com.nightonke.saver.model.User)7 File (java.io.File)7 Bitmap (android.graphics.Bitmap)6 FutureCallback (com.koushikdutta.async.future.FutureCallback)6 FileNotFoundException (java.io.FileNotFoundException)6 FileInputStream (java.io.FileInputStream)5 BmobFile (cn.bmob.v3.datatype.BmobFile)4 IOException (java.io.IOException)3 DeleteListener (cn.bmob.v3.listener.DeleteListener)1 SaveListener (cn.bmob.v3.listener.SaveListener)1 UpdateListener (cn.bmob.v3.listener.UpdateListener)1 UploadFileListener (cn.bmob.v3.listener.UploadFileListener)1 BmobProFile (com.bmob.BmobProFile)1 ParseException (java.text.ParseException)1